Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does :-> mean in a haskell type specification

Tags:

haskell

I've seen this in a few places:

data T = T a :-> b

Notably in quickcheck we have

data Fun a b = Fun (a :-> b, b) (a -> b)

What is the :-> and how does it differ from ->?

like image 857
jwoolard Avatar asked Aug 18 '11 08:08

jwoolard


People also ask

What does -> mean in Haskell?

(->) 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.

What is Haskell function type?

Haskell is a functional language and it is strictly typed, which means the data type used in the entire application will be known to the compiler at compile time.

What is type declaration in Haskell?

Haskell has three basic ways to declare a new type: The data declaration, which defines new data types. The type declaration for type synonyms, that is, alternative names for existing types. The newtype declaration, which defines new data types equivalent to existing ones.


2 Answers

Operators beginning with a colon is a constructor or type name. In this case it is a type name for a data type specific to quickcheck, but in general the symbol :-> could be used for any constructor or type name as you like (it's not part of the language proper).

The definition of :-> in quickcheck:

-- the type of possibly partial concrete functions
data a :-> c where
  Pair  :: (a :-> (b :-> c)) -> ((a,b) :-> c)
  (:+:) :: (a :-> c) -> (b :-> c) -> (Either a b :-> c)
  Unit  :: c -> (() :-> c)
  Nil   :: a :-> c
  Table :: Eq a => [(a,c)] -> (a :-> c)
  Map   :: (a -> b) -> (b -> a) -> (b :-> c) -> (a :-> c)
like image 184
Owen Avatar answered Oct 23 '22 03:10

Owen


Answered my own question: first saw this as

data Edge = i :-> i

:-> is of course the constructor.

like image 24
jwoolard Avatar answered Oct 23 '22 02:10

jwoolard