I did some reading and got through all the recommended chapters of Learn You A Haskell and Real World Haskell.
Playing around
I also explored several concepts, including composing functions that take multiple arguments. I did not find evidence of any built-in functions, so I ended up defining this:
composeDiadic :: (c -> d) -> (a -> b -> c) -> a -> b -> d
composeDiadic f g x y = f (g x y)
(.:) = composeDiadic
I wanted to make this because I was playing around with lists of lists, and found intersperse
, concat
, and a function that combines the two: intercalate
. I wanted to rewrite intercalate
as a little exercise, but it did not like concat . intersperse
since (.)
does not expect any function that takes 2 arguments.
Lecture 2
Algebraic data types are defined like so:
data MyType = Constructor1
| Constructor2 Type1
| Constructor3 TypeA TypeB
deriving Show
- add
deriving Show
after a data type definition to automatically make it able to be displayed as a string. - type constructors and data constructors inhabit different namespaces, so single-constructor types often use the same name for both.
Pattern Matching
- Parens are needed for pattern matching around a data constructor that has one or more parameters.
- Bind the whole value to a name using something like
myFuncton name@(Constructor2 a) = <do something with name>