Enter parameters in type and data constructors

If I understand correctly,

data Int = 1 | 2 | 3 | 4 | ...

All things on the right are simply meanings.

Further,

data Maybe b = Nothing
             | Just b

Do bin Maybe band bin Just bmean the same thing? For me it looks like this: bc Maybe bis a variable of type, and bc Just bis a variable of type b value .

+4
source share
1 answer

data Maybe bmeans that the type is generic and that bis a variable of generic type.

Just bdoes indicate that one way to create a value Maybe bis to provide a type value b.

Prelude> Just "foo"
Just "foo"
Prelude> Just 42
Just 42

Just "Foo" Maybe String, type b String. Haskell .

, , Just 42, , :

Prelude> :t Just 42
Just 42 :: Num a => Maybe a

, Maybe a, a Num. , "".

( , data Int, ...)

0

Source: https://habr.com/ru/post/1680926/


All Articles