Info on some haskell packages.
Property
: Invariants that would be tested fuzzilyGen a
: Generator for random values of a
type Gen = GenT Identity
MonadGen
: Class of monads which can generate input data
for testsGen.sample
See:
λ> :t G.int $ R.constant 0 10
G.int $ R.constant 0 10 :: MonadGen m => m Int
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
Parsec
: non-transformer version of ParsecT
<|>
<*>
<$>
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:
https://hackage.haskell.org/package/lens-tutorial-1.0.5/docs/Control-Lens-Tutorial.html
^.
val^.attr.subattr
is like obj.attr.subattr
in Pythonval ^. (attr . subattr)
^.
is same as view
:
x ^. l = view l x
lens
: lot of dependenciesmicrolens
or lens-simple
: light-weight
form of lens
with fewer dependencies—
%=
:
>>> 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
over
: setterview
: getterIt'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.
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 |
A package for making TUIs.
<+>
: Vertical split<=>
: Horizontal splitTimers can be made with BChan
More:
<?>
: parser <?> err_msg
err_msg
shown when parsing with parser
failsFocus is on 'changes' rather than 'snapshots'.
–
Git analogues:
git | darcs |
---|---|
commit | record |