modelling data Flashcards
homogenious
same data type
heterogenious
different data types
type keyword
allows you to create a type alias
what is an advantage of creating a type alias
means you dont have to write out the type multiple times
type alias as transparent
can pass values with the same structure instead of the alias
can change the internal values as much as you want
newtype keyword
like type but defines a new type rather than an alias
what is a positive and negative of the newtype keyword
allows you to maintain data constraints
cant be used interchangeably by the types its made up of
why do we use the deriving keyword
when defining new types we want to avoid making the type an instance of the type class we want to use it with (e.g. deriving(show))
data keyword
defines a new data type
allows you to do things that have been build into other languages separately
data + enumeration
separates the different values with a |
enumeration
a list of all possible values a type can have
type constructors
allows you to make a value of a new type/datatype
becomes another function and can be used like one anywhere
value constructor
a function that produces a value of the type from arguments inputted
smart construction
functions that take the necessary data to create a value of a type and returns the value if the constraints are valid
how do we stop smart construction from crashing if the constraints arent valid
using maybe or either
parametised types
a generic type; uses a type variable e.g. a
what is a benefit of parametised types
allows us to write flexible and reusable data types