I'm reading a following datatype:
data Ne
= NVar Id
| Ne :.. (Clos Term)
| NSplit Ne (Bind (Bind (Clos Term)))
| NCase Ne (Clos [(Label, Term)])
| NForce Ne
| NUnfold Ne (Bind (Clos Term))
deriving (Show, Eq)
What is :.. in the second member declaration?
(->) is often called the "function arrow" or "function type constructor", and while it does have some special syntax, there's not that much special about it. It's essentially an infix type operator. Give it two types, and it gives you the type of functions between those types.
It is a List constructor function. It is used for prepending any value in front of the list.
The == is an operator for comparing if two things are equal. It is quite normal haskell function with type "Eq a => a -> a -> Bool". The type tells that it works on every type of a value that implements Eq typeclass, so it is kind of overloaded.
The left arrow gets used in do notation as something similar to variable binding, in list comprehensions for the same (I'm assuming they are the same, as list comprehensions look like condensed do blocks), and in pattern guards, which have the form (p <- e). All of those constructs bind a new variable.
The name of a constructor can either be alpha-numeric starting with a capital letter or symbolic starting with a colon. In the latter case the operator will be used infix just like infix functions.
So :..
is an infix constructor for the Ne
type, which takes an argument of type Ne
(left operand) and one of type Clos Term
(right operand).
:..
is one of the constructors for the algebraic datatype Ne
. A constructor name consisting of punctuation and starting with :
becomes an infix operator. Try this:
module Main where
data List a = Nil
| a :.. (List a)
deriving Show
main = print (1 :.. (2 :.. Nil))
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