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
it allows us to automatically generate instances for certain type classes, to be used within our own data types without having to write the instance code manually. (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
enumeration: a list of all possible values a type can have and when using data theyre separated by |
enumeration
a list of all possible values a type can have
type constructors
a function that allows you to make a value of a new type/datatype
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