Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#12507 closed bug (fixed)

Can't deduce implicit parameter

Reported by: Iceland_jack Owned by:
Priority: normal Milestone:
Component: Compiler Version: 8.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: typecheck/should_compile/T12507
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

I tried running a gist

{-# LANGUAGE GADTs, ConstraintKinds, Rank2Types, ImplicitParams #-}

data Rec fields where
  Rec :: fields => Rec fields

infixr 1 ?
(?) :: Rec fields -> (fields => r) -> r
Rec ? e = e

record :: Rec (?a :: Int, ?b :: String)
record = Rec where ?a=42
                   ?b="hey"

access :: Int
access = record ? ?a

and got

$ ghci -ignore-dot-ghci tCHB.hs 
GHCi, version 8.0.1: http://www.haskell.org/ghc/  :? for help
[1 of 1] Compiling Main             ( tCHB.hs, interpreted )

tCHB.hs:15:19: error:
    • Could not deduce: ?a::Int
        arising from a use of implicit parameter ‘?a’
      from the context: (?a::Int, ?b::String)
        bound by a type expected by the context:
                   (?a::Int, ?b::String) => Int
        at tCHB.hs:15:10-20
    • In the second argument of ‘(?)’, namely ‘?a’
      In the expression: record ? ?a
      In an equation for ‘access’: access = record ? ?a
Failed, modules loaded: none.
Prelude> 

I would certainly expect the context (?a::Int, ?b::String) to imply ?a::Int?

Change History (4)

comment:1 Changed 3 years ago by Iceland_jack

Works with Given from reflection:

record :: Rec (Given Int, Given String)
record = give (1::Int) (give "hi" Rec)

access :: Int
access = record ? given @Int

comment:2 Changed 3 years ago by Simon Peyton Jones <simonpj@…>

In cdbc73ae/ghc:

Test Trac #12507

This is now working apparently.  It relates to when a
polymorphic function gets instantiated, under some
implicit paramter bindings.

comment:3 Changed 3 years ago by simonpj

Resolution: fixed
Status: newclosed

comment:4 Changed 3 years ago by simonpj

Test Case: typecheck/should_compile/T12507
Note: See TracTickets for help on using tickets.