I did some reading and got through all the recommended chapters of Learn You A Haskell and Real World Haskell.
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
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.
Algebraic data types are defined like so:
data MyType = Constructor1 | Constructor2 Type1 | Constructor3 TypeA TypeB deriving Show
deriving Showafter 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.
- 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>