A cheatsheet to regexes in Haskell April 11, 2019 « Previous post Next post » UPDATE: This cheatsheet is now part of the documentation for regex-tdfa! While Haskell is great for writing parsers, sometimes the simplest solution is just to do some text. Haskell Cheat Sheet This cheat sheet attempts to lay out the fundamen-tal elements of the Haskell language and libraries. It should serve as a reference to both those learn-ing Haskell and those who are familiar with it, but maybe can't remember all the varieties of syntax and functionality. It is presented as both an executable Haskell file. As shown earlier, Haskell provides a the deriving mechanism for making it easier to define instances of typeclasses, such as Show, Read, Eq, Ord, Enum. Constructor names are printed and read as written as written in the datadeclaration, two values are. Haskell CheatSheet Written and maintained by Justin Bailey. The cheat sheet is a PDF included in the source distribution. If you installed this package through cabal install, run 'cheatsheet.exe' to find where the PDF was installed.
The below is a tiny fraction of what is available online; for more, start at haskell.org.
Cheat Sheet
Editor Plugins
Books
Real World Haskell by Bryan O' Sullivan, John Goerzen, and Don Stewart
The Haskell School of Expression by Paul Hudak
Programming in Haskell by Graham Hutton
Learn You a Haskell by Miran Lipovača
Tutorials
- Monad Tutorial by Graham Hutton
Fancy Types and Verification
Courses
- Dartmouth Problem Solving with Computer Science
- UPenn Advanced Programming
- Stanford Programming Languages
- Princeton Programming Languages
Miscellaneous
API Search Engines: HoogleHayoo
Haskell modes: VimEmacs
Cheat Sheet Pdf
Monad Examples
- List
- Maybe/Optional
- Either
- Try (Scala specialized Either that catches exceptions)
- Future
- Observable/Signal
Async
One | Many | |
---|---|---|
Synchronous | T/Try[T] | Iterable[T] |
Asynchronous | Future[T] | Observable[T] |
Miscellaneous
API Search Engines: HoogleHayoo
Haskell modes: VimEmacs
Cheat Sheet Pdf
Monad Examples
- List
- Maybe/Optional
- Either
- Try (Scala specialized Either that catches exceptions)
- Future
- Observable/Signal
Async
One | Many | |
---|---|---|
Synchronous | T/Try[T] | Iterable[T] |
Asynchronous | Future[T] | Observable[T] |
Haskell
data type
Haskell name | Haskell def | Equivalent in Java or similar |
---|---|---|
type class | class Smthg | Interface/Protocol |
type constructor | data Smthg a | Generic |
concrete type | Smthg Int data Smthg | Parametrized Generic |
type synonym | type | typealias |
data type | data Smthg param | Class |
instance of type class | instance (TypeClass) type data deriving (TypeClass) | implements |
Concepts
Markdown Cheatsheet Pdf
Name | Haskell | type | desciption |
---|---|---|---|
Functor | fmap | a->b -> f a -> f b | map (infix synonym: <$>) |
Applicative(Functor) | pure | a -> f a | id/constructor, lift a value |
<*> | f (a -> b) -> f a -> f b | sequential application, apply a functored map | |
Monoid | mempty | a | id |
mappend | a -> a -> a | combine 2 | |
mconcat | [a] -> a | fold | |
Monad | return | a -> m a | pure |
>>= | m a -> (a -> m b) -> m b | bind, chain, flatmap | |
>> | m a -> m b -> m b | discard first |
Instances of 'Monad' should satisfy the following laws:
Haskell Syntax
Instances of both 'Monad' and 'Functor' should additionally satisfy the law: