This appears to be a case of premature documentation. According to this blog post, this syntax is part of a feature recently added to GHC HEAD, but it's not yet valid in any released version of GHC.
Type Families extension does not work as described
-
14-04-2022 - |
Question
On the Haskell wiki page for Type Families, there is the following list of examples:
type family F a :: *
type instance F [Int] = Int -- OK!
type instance F String = Char -- OK!
type instance F (F a) = a -- WRONG: type parameter mentions a type family
type instance F (forall a. (a, b)) = b -- WRONG: a forall type appears in a type parameter
type instance F Float = forall a.a -- WRONG: right-hand side may not be a forall type
type instance where -- OK!
F (Maybe Int) = Int
F (Maybe Bool) = Bool
F (Maybe a) = String
type instance where -- WRONG: conflicts with earlier instances (see below)
F Int = Float
F a = [a]
type family G a b :: * -> *
type instance G Int = (,) -- WRONG: must be two type parameters
type instance G Int Char Float = Double -- WRONG: must be two type parameters
This demonstrates that type instance where
is valid syntax under this extension. However the following code does not compile for me with GHC 7.4.2:
{-# LANGUAGE TypeFamilies #-}
type family F a :: *
type instance where
F (Maybe Int) = Int
F (Maybe Bool) = Bool
F (Maybe a) = String
The error message is:
test.hs:4:15: parse error on input `where'
Since this is a parsing error, it looks like that syntax is not supported, so am I missing a requisite extension, or is something else amiss?
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow