I think I have a problem with Haskell type inference.
I made my own data type and made it instance of the class Read
. My data type is actually take an other type as parameter, it's a type parameter.
I redefined readPresc
in a way that parse the string and give back my new data. When I write:
read "string that represent MyType a" :: MyType a
it works perfectly fine (at least it does what I expected)
Now I have a function, let's call it insert
, that takes an element of type a
, MyType a
, and gives back a new MyTape a
.
insert :: a -> MyType a -> a
but when I write:
insert 3 "string that rapresent MyType Int"
I got Ambigous type
.
How can I tell haskell to infer to the read
the same type that is the parameter of the insert?
insert 3 (read "string representation")
? – icktoofayread "bla blah blah" :: MyType
suggestsMyType
is a type, butinsert :: a -> MyType a -> a
impliesMyType
is a type constructor. – AndrewC