Safe Haskell | None |
---|---|
Language | Haskell2010 |
A more strongly typed alternative to Match
Synopsis
- matchNix :: QuasiQuoter
- matchNixLoc :: QuasiQuoter
- newtype TypedMatcher (opts :: [Symbol]) (reqs :: [Symbol]) t = TypedMatcher {
- unTypedMatcher :: WithHoles t Text
- newtype TypedMatch (opts :: [Symbol]) (reqs :: [Symbol]) a = TypedMatch [(Text, a)]
- get :: forall x opts reqs a. (Elem "Required" x reqs, KnownSymbol x) => TypedMatch opts reqs a -> a
- getOptional :: forall x opts reqs a. (Elem "Optional" x opts, KnownSymbol x) => TypedMatch opts reqs a -> Maybe a
- matchTyped :: Matchable t => TypedMatcher opts reqs t -> Fix t -> Maybe (TypedMatch opts reqs (Fix t))
- findMatchesTyped :: Matchable t => TypedMatcher opts reqs t -> Fix t -> [(Fix t, TypedMatch opts reqs (Fix t))]
Documentation
matchNix :: QuasiQuoter Source #
A QuasiQuoter for safely generating TypedMatcher
s from nix source
The expression has the type
where TypedMatcher
opts reqs NExprF
opts
and reqs
are the optional and required holes from the source expression.
The pattern, if matched, will bring into scope variables named according to
the holes present in the expression. These will have type NExpr
if they
are required, and Maybe
if they are optional.NExpr
This requires ViewPatterns, TypeApplications and DataKinds
>>>
case [nix|{a="hello";}|] of [matchNix|{a=^a;}|] -> a
Fix (NStr (DoubleQuoted [Plain "hello"]))
>>>
:t [matchNix|{a = ^a; b = {c = ^c; _d = ^d;};}|]
[matchNix|{a = ^a; b = {c = ^c; _d = ^d;};}|] :: TypedMatcher '["d"] '["a", "c"] NExprF
>>>
[matchNix|let a = ^a; _b = ^b; in x|] = undefined
>>>
:t (a, b)
(a, b) :: (Fix NExprF, Maybe (Fix NExprF))
matchNixLoc :: QuasiQuoter Source #
A QuasiQuoter for safely generating TypedMatcher
s from nix source along
with source location annotations
The expression has the type
where
TypedMatcher
opts reqs NExprLocF
opts
and reqs
are the optional and required holes from the source
expression.
This requires ViewPatterns, TypeApplications and DataKinds
The pattern, if matched, will bring into scope variables named according to
the holes present in the expression. These will have type NExprLoc
if they
are required, and Maybe
if they are optional.NExprLoc
newtype TypedMatcher (opts :: [Symbol]) (reqs :: [Symbol]) t Source #
A matcher with the names of the required and optional holes encoded at the type level.
newtype TypedMatch (opts :: [Symbol]) (reqs :: [Symbol]) a Source #
The results of matching with a TypedMatcher
. The values in the required
list are guaranteed to be present. The values in the optional list may be
present. Use get
and getOptional
to extract them safely.
TypedMatch [(Text, a)] |
get :: forall x opts reqs a. (Elem "Required" x reqs, KnownSymbol x) => TypedMatch opts reqs a -> a Source #
Extract a required key from a match
getOptional :: forall x opts reqs a. (Elem "Optional" x opts, KnownSymbol x) => TypedMatch opts reqs a -> Maybe a Source #
Maybe extract an optional key from a match
matchTyped :: Matchable t => TypedMatcher opts reqs t -> Fix t -> Maybe (TypedMatch opts reqs (Fix t)) Source #
A typed version of match
findMatchesTyped :: Matchable t => TypedMatcher opts reqs t -> Fix t -> [(Fix t, TypedMatch opts reqs (Fix t))] Source #
A typed version of findMatches