I have a type:
type DifferentiableFunction n a = (Function n a, List n (Function n a), String)
Elsewhere I define:
data Something where
Operator :: Something -> (forall a . Floating a => DifferentiableFunction n a) -> Something
Now I try to pattern match:
case something of
(Operator s f) -> let (_, _, l) = f in l
I get Could not deduce (Floating a0) arising from a use of ‘f’
. I don't understand why this is happening.
The problem is that
let (_, _. l) = f in l
does not specify what type to use forf
: it could beDifferentiableFunction n Double
orDifferentiableFunction n Float
or something else altogether. Because you only use a part which does not depend ona
(l
is just aString
, no matter whata
is), the compiler is unable to decide what typef
should have (a
is ambigious, i.e. the compile does not know what to pick fora
).The solution therefore is to give an explicit type signature for f:
Or alternatively, lift the
String
out of the forall:Now you can get the
String
without needing to pick a specifica
, because it really is independent ofa
.