Learning project for haskell
- Write functions...
- not methods
- not classes
- not procedures
- ...that compose...
- higher-order functions
- combinators
- abstractions should compose
- can be domain specific
- ...mostly small.
- prefer lots of little functions
- build programs out of small pieces
- rethink “single responsibility”
- instead of grouping functions by domain as you would in Object Oriented Programming
- try to make functions more generic so that they can be decoupled from the domain
- brew install haskell-stack
- stack new haskell-fundamentals
- cd haskell-fundamentals
- stack test
- git init
- git add --all
- git commit -m "Created haskell-fundamentals project"
- git remote add origin [email protected]:cjdev/haskell-fundamentals.git
- git push -u origin master
- choose in entry point to run, for example
- src/HelloAlice.hs
- run it as a script, like so
- stack runhaskell src/HelloAlice.hs
stack test --file-watch
- for example, to turn on overloaded strings
- in file
- {-# LANGUAGE OverloadedStrings #-}
- in ghci
- :set -XOverloadedStrings
- Functions
- Data
- Collection
- Tuples
- Flow Control
- Maybe
- Fold and Tail Recursion
- Functor
- Applicative
- Monad
- Semigroup
- Monoid
- Test with freer — test, stubs
- Test with mtl — test, stubs
- Alternative
- Parser Combinators
- Validation
- List Comprehension
- Laziness
Hoogle is a search engine for haskell packages. There is a hosted version at
hoogle.haskell.org. You can also set up a local index. Instructions here
- Applicative is subclass of Functor
- Alternative is subclass of Applicative
- Monad is a subclass of Applicative
- MonadPlus is a subclass of both Alternative and Monad
- Monoid is a subclass of Semigroup
- Bool
- an enumeration of True and False
- Char
- a unicode code point between 0 and 1114111 (17 planes with 2^16 code points per plane = 1114112)
- String
- a list of Char
- Data.Text
- capabilities of a String, without the performance limitations of a singly linked list
- List
- represented with brackets [,]
- a singly linked list
- Tuple
- represented with parenthesis (,)
- an algebraic data type whose members are accessed by position but not name
- the larger the tuple, the less likely there exists language and library support
- languange guarantees support of at least size 15,
- Unit
- represented as ()
- a type with only a single value
- useful when the return value does not matter
- IO
- an operation whose behavior is not determined by the program, but rather the environment within which the program is run (for example, the operating system)
- Integer
- an arbitrary precision integer
- Int
- a fixed precison integer, 30 bits of precision guaranteed, most likely matches your environment's word size
- Float
- IEEE 754 single precision floating point
- Double
- IEEE 754 double precision floating point
- Rational
- a ratio of Integers
$ function application (used to avoid parentheses)
& reverse function application (like a Unix pipe)
. right-to-left function composition
++ list append
<> semigroup append
<$> infix fmap (like ($) for functors)
<&> flipped infix fmap (like (&) for functors)
<*> applicative apply
<$ replace all elements with a value (fmap . const)
$> flipped version of (<$)
<* like (<*>), but ignore result of second argument
*> like (<*>), but ignore result of first argument
>>= bind
=<< flipped bind
>=> left-to-right monadic composition
<=< right-to-left monadic composition
<|> alternative or
<- bind (when used in do block)
~ type equality constraint
=> is a constraint on
~> natural transformation
{
"window.zoomLevel": 2,
"editor.tabSize": 2,
"editor.detectIndentation": false,
"files.trimTrailingWhitespace": true
}