update-nix-fetchgit-0.2.9: A program to update fetchgit values in Nix expressions
Safe HaskellNone
LanguageHaskell2010

Nix.Match.Typed

Description

A more strongly typed alternative to Match

Synopsis

Documentation

matchNix :: QuasiQuoter Source #

A QuasiQuoter for safely generating TypedMatchers from nix source

The expression has the type TypedMatcher opts reqs NExprF where 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 NExpr if they are optional.

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 TypedMatchers from nix source along with source location annotations

The expression has the type TypedMatcher opts reqs NExprLocF where 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 NExprLoc if they are optional.

newtype TypedMatcher (opts :: [Symbol]) (reqs :: [Symbol]) t Source #

A matcher with the names of the required and optional holes encoded at the type level.

Constructors

TypedMatcher 

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.

Constructors

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