Haskell packages


Info on some haskell packages.


Hedgehog

See:


λ> :t G.int $ R.constant 0 10
G.int $ R.constant 0 10 :: MonadGen m => m Int

Megaparsec

Monad transformer: Think of it as a function taking a monad and returning another monad.

Parsec e inp res = ParsecT e inp Identity res

-- Parser res = Parsec Void Text res
type Parser = Parsec Void Text

Parser a means a parser whose result after successful parsing is of type a.


import Data.Void

--                         +-- Input type
--                         |
--                         v
type Parser = Parsec Void Text
--                    ^
--                    |
--                Error component

Info

Functions

Operator table

From https://markkarpov.com/tutorial/megaparsec.html:

data Operator m a
  = InfixN  (m (a -> a -> a)) -- ^ Non-associative infix
  | InfixL  (m (a -> a -> a)) -- ^ Left-associative infix
  | InfixR  (m (a -> a -> a)) -- ^ Right-associative infix
  | Prefix  (m (a -> a))      -- ^ Prefix
  | Postfix (m (a -> a))      -- ^ Postfix

See:

Lens

https://hackage.haskell.org/package/lens-tutorial-1.0.5/docs/Control-Lens-Tutorial.html

%=:

>>> execState (do _1 %= f;_2 %= g) (a,b)
(f a, g b)

>>> execState (do both %= f) (a,b)
(f a, f b)

.=:

>>> execState (do _1 .= c;_2 %= d) (a,b)
(c, d)

>>> execState (do both %= c) (a,b)
(c, c)

More concepts:

Functions: re, unto, set, .=,


One possible use of lens: getters-setters when using nested record types

It's like this:

data Lens a b = Lens
{ view :: a -> b
, over :: (b -> b) -> (a -> a)
}

Create lens for a type with:

makeLenses ''<bigtype>
makeLenses ''<smalltype>

This is made possible with TemplateHaskell.

Field names in the record type should have underscore prefix.

Containers

Seq (as in list) type from Data.Sequence of 'containers' package.

<│ Add element to left end of a seq a -> Seq a -> Seq a
│> Add element to right end of a seq a -> Seq a -> Seq a
>< Concatenate two sequnces Seq a -> Seq a -> Seq a

Bricks

A package for making TUIs.

Timers can be made with BChan

More:

Parsec

Darcs

https://darcs.net/QuickStart

Focus is on 'changes' rather than 'snapshots'.

Git analogues:

git darcs
commit record