Haskell $ operator gives data constructor error

1:([2]) works as expected.

1:$[2] gives <interactive>:15:2: Not in scope: data constructor `:$'

I thought the statement $bracketed everything after it: Haskell: the difference between the two. (dot) and $ (dollar sign)

What's happening?

+4
source share
3 answers

The operator is $not syntax, it is just a normal function, like any other. When you write

1 :$ [2]

The first problem that the compiler sees is that it :$appears as its own operator (consider + +versus ++, these are different things), but :$it is not defined anywhere.

If you should have written

1 : $ [2]

, , , , 1 + * 2 . . $

f $ x = f x

, , . .

+9

$ .

1: , (1:) , (1:) $ [2], 1: $ [2].

( , , :$ - , , , :, , , , .)

+10

$ literally does not put parentheses around arbitrary code, but changes the order in which functions are evaluated (for example, parentheses).

+6
source

All Articles