Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Illegal binding of built-in syntax: `:`

Tags:

stream

haskell

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?

like image 428
Сергей Кузминский Avatar asked May 06 '13 17:05

Сергей Кузминский


1 Answers

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)
like image 148
C. A. McCann Avatar answered Oct 11 '22 02:10

C. A. McCann