match package:vinyl
Pattern match on a CoRec by specifying handlers for each case. Note
that the order of the Handlers has to match the type level list
(t:ts).
>>> :{
let testCoRec = Col (Identity False) :: CoRec Identity [Int, String, Bool] in
match testCoRec $
(H $ \i -> "my Int is the successor of " ++ show (i - 1))
:& (H $ \s -> "my String is: " ++ s)
:& (H $ \b -> "my Bool is not: " ++ show (not b) ++ " thus it is " ++ show b)
:& RNil
:}
"my Bool is not: True thus it is False"
Handle a single variant of a
CoRec: either the function is
applied to the variant or the type of the
CoRec is refined to
reflect the fact that the variant is
not compatible with the
type of the would-be handler
Helper for handling a variant of a
CoRec: either the function
is applied to the variant or the type of the
CoRec is refined
to reflect the fact that the variant is
not compatible with the
type of the would-be handler.
Given that
xs and
ys have the same length, and
mapping
f over
xs and
g over
ys
produces lists whose elements are pairwise
Coercible,
ARec
f xs and
ARec g ys are
Coercible.
AllRepsMatch f xs g ys means that
xs and
ys
have the same lengths, and that mapping
f over
xs
and
g over
ys produces lists whose corresponding
elements are
Coercible with each other. For example, the
following hold:
AllRepsMatch Proxy '[1,2,3] Proxy '[4,5,6] AllRepsMatch
Sum '[Int,Word] Identity '[Min Int, Max Word]
Given that for each element x in the list xs,