Name: stack-prism
Owner: Wire Swiss GmbH
Description: Haskell lens prisms that use stack types
Created: 2018-04-09 15:57:32.0
Updated: 2018-04-18 15:32:15.0
Pushed: 2018-04-10 09:35:18.0
Homepage: null
Size: 49
Language: Haskell
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
A Haskell library for expressing and deriving stack prisms.
A stack prism is a bidirectional isomorphism that is partial in the backward direction. These prisms are compatible with the lens library.
Stack prisms can express constructor-deconstructor pairs. For example:
:: StackPrism t ([a] :- t)
= stackPrism f g
ere
f t = [] :- t
g ([] :- t) = Just t
g _ = Nothing
:: StackPrism (a :- [a] :- t) ([a] :- t)
= stackPrism f g
ere
f (x :- xs :- t) = (x : xs) :- t
g ((x : xs) :- t) = Just (x :- xs :- t)
g _ = Nothing
Here :-
can be read as 'cons', forming a stack of values. For example, nil
pushes []
onto the stack; or, in the backward direction, tries to remove []
from the stack. cons
takes a head x
and tail xs
from the stack and pushes
x : xs
onto the stack, or, in the backward direction, takes x : xs
from the
stack and replaces it with its two individual components.
Every constructor has its own stack prism version. You don't have to write them
by hand; you can automatically generate them, either using Template Haskell
(see module Data.StackPrism.TH
) or using GHC generic programming (see
module Data.StackPrism.Generic
).
Representing constructor-destructor pairs as stack manipulators allows them to be composed more easily.