Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/err Secret

Created December 8, 2021 19:52
Show Gist options
  • Save dminuoso/ea39c159219afcb4ba56fef01307da12 to your computer and use it in GitHub Desktop.
Save dminuoso/ea39c159219afcb4ba56fef01307da12 to your computer and use it in GitHub Desktop.
foo.hs:30:8: error:
• Couldn't match type ‘Inner mode f’ with ‘Inner mode f0’
Expected type: ArgF mode -> Inner mode f0
Actual type: ArgF mode -> Inner mode f
NB: ‘Inner’ is a non-injective type family
The type variable ‘f0’ is ambiguous
• In the ambiguity check for ‘doc’
To defer the ambiguity check to use sites, enable AllowAmbiguousTypes
In the type signature: doc :: Sel f -> String
|
30 | doc :: Sel f -> String
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
data Mode = Field | Descr
type family Inner mode field where
Inner Field f = f
Inner Descr f = String
data ArgF (f :: Mode) = ArgF
{ field1 :: Inner f Char
, field2 :: Inner f Int
}
someArg :: ArgF Field
someArg = ArgF
{ field1 = 'c'
, field2 = 42 }
argDescr :: ArgF Descr
argDescr = ArgF
{ field1 = "Some field 1"
, field2 = "Another fancy field"
}
type Sel f = forall mode. (ArgF mode -> Inner mode f)
doc :: Sel f -> String
doc sel = sel argDescr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment