I need to build custom Stream data type. It's like list data type, but for infinite lists only (without empty list possibility).
I found list data type -
data [] a = a : [a] | []
and I wrote this:
data Stream a = a : (Stream a)
but GHCi gives error message:
Illegal binding of built-in syntax: :
what's wrong this my data type declaration?
The constructor (:)
is built-in syntax and specific to the standard list type, unlike much of the standard "built-in" types that are just regular types defined in the standard library.
So, you'll need to use a different constructor for your stream type. (:|)
and (:<)
are versions I've seen, so something like this:
data Stream a = a :< Stream a
...should work fine.
You could also drop the infix constructor entirely if you prefer:
data Stream a = Stream a (Stream a)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With