I'm trying to implement (a simplified version of) Representable for my data type, but I'm not allowed to use the first data type parameter in the definition:
question.hs
-----------
{-# LANGUAGE TypeFamilies #-}
class Representable f where
type Rep f :: *
tabulate :: (Rep f -> x) -> f x
index :: f x -> Rep f -> x
data F a b = F a b
instance Representable (F a) where
-- ^
-- orfeas: It's right here, ghc!
type Rep (F a) = a
tabulate g = F a (g a)
-- ^ ^
-- ghc: a not in scope :(
index (F a b) = g where g a = b
main = return ()
How can I make ghc see a inside the instance implementation?
I expected the above to compile successfully, but I got this instead:
ghc -dynamic question.hs
[1 of 1] Compiling Main ( question.hs, question.o )
question.hs:15:18: error: Variable not in scope: a
|
14 | tabulate g = F a (g a)
| ^
question.hs:15:23: error: Variable not in scope: a
|
14 | tabulate g = F a (g a)
| ^
tabulate g = F a (g a),Ftakes values, not types, andais a type.