简体   繁体   中英

Does (->) have a data constructor?

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

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 ( fe ) to deconstruct (“use”) a function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM