Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does (->) have a data constructor?

Tags:

haskell

I know (->) type is defined as data (->) t1 t2. I wonder is there a data constructor function for the (->) type?

like image 516
user28522 Avatar asked Apr 08 '17 16:04

user28522


People also ask

What is a data constructor?

A data constructor is a "function" that takes 0 or more values and gives you back a new value. A type constructor is a "function" that takes 0 or more types and gives you back a new type.

What is a constructor in DBMS?

A constructor is a special method of a class or structure in object-oriented programming that initializes a newly created object of that type. Whenever an object is created, the constructor is called automatically.

What is a data constructor Haskell?

Data constructors are first class values in Haskell and actually have a type. For instance, the type of the Left constructor of the Either data type is: Left :: a -> Either a b. As first class values, they may be passed to functions, held in a list, be data elements of other algebraic data types and so forth.

What is a Typeclass in Haskell?

What's a typeclass in Haskell? A typeclass defines a set of methods that is shared across multiple types. For a type to belong to a typeclass, it needs to implement the methods of that typeclass. These implementations are ad-hoc: methods can have different implementations for different types.


1 Answers

No, (->) does not have a data constructor, as functions are not algebraic data types. The fact that ghci says

Prelude> :inf (->)
data (->) t1 t2     -- Defined in ‘GHC.Prim’

is a bit of a lie, because that is not how (->) is being defined. In fact, there is no definition around, as functions are a very primitive notion.

In some sense, a lambda expression \x -> e (or, equivalently, a function definition) is the “constructor” of values of type a -> b, but you cannot pattern match on that. Instead, you use function applications (f e) to deconstruct (“use”) a function.

like image 184
Joachim Breitner Avatar answered Oct 23 '22 19:10

Joachim Breitner