Hello i have the following problem:
I am constructing a parametric newtype over a method and i do not know how to explictly tell GHCI : I want you to instiantiate this newtype using this type parameter
newtype M a = M {fu::a->Int}
var = M (\s-> length (s:"asa")) #tell him i want the type parameter to be Char
b = (fu var) 'c'
What i expect to get is : 4 because length 'c':"aaa"==4
What i do get is :
interactive>:118:5: error:
* Couldn't match expected type `A [Char]'
with actual type `Ghci30.A [Char]'
NB: `Ghci30.A' is defined at <interactive>:100:1-25
`A' is defined at <interactive>:109:1-25
* In the first argument of `fu', namely `b'
In the expression: (fu b) "asa"
In an equation for `it': it = (fu b) "asa"
When you see names like
Ghci30.A [Char], this means that you have redefined your typeAin GHCi. This would not be an issue if you used a proper.hsfile and reloaded it.Consider this GHCi session:
What should be the output? The type of
xisA, but it's not the same typeAhaving aCharinside. GHCi will print the type asYou won't get the error again if you (re-)define
xafter you redefine the typeA.If your case, the
xto be redefined is likelyfu, which is still referring to the oldA. Check it with:t fu: if it mentionsGhci30.A, that's it.For non trivial definitions, I'd recommend to use a
.hsfile and reload it, so to avoid any trouble.