| Start |
|---|
| Creating a data type with value constructor parameters Value constructors are functions that return a value of a data type. Because of this, just like any other function, they can take one or more parameters: Let's check the type of the prints which proves that Creating variables of our custom type |
| Creating a data type with type parameters Type constructors can take one or more type parameters: Type parameters in Haskell must begin with a lowercase letter. Our custom data type is not a real type yet. In order to create values of our type, we must substitute all type parameters with actual types. Because Creating variables of our custom type |
| Creating a simple data type The easiest way to create a custom data type in Haskell is to use the The name of the type is specified between Define a type called Creating variables of our custom typeThe above statement creates a variable named prints |
| Custom data type with record parameters Assume we want to create a data type Person, which has a first and last name, an age, a phone number, a street, a zip code and a town. We could write If we want now to get the phone number, we need to make a function Well, this is no fun. We can do better using parameters: Now we get the function We can now do whatever we want, eg: We can also bind the phone number by Pattern Matching (opens new window): For easy use of the parameters see RecordWildCards (opens new window) |
Read Article
https://develop.horje.com/learn/1434/reference