summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabrielGonzalez <>2020-09-11 05:04:00 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2020-09-11 05:04:00 (GMT)
commit30d2290eaf14a82b6ea8da9e95091af76bb9815e (patch)
tree9f2cb7c232e040ca88db1848d90516a26d2e9534
parent85b8624ad186742b246edcc84046626c9fb1a24d (diff)
version 1.1.17HEAD1.1.17master
-rw-r--r--dhall-nix.cabal4
-rw-r--r--src/Dhall/Nix.hs21
2 files changed, 15 insertions, 10 deletions
diff --git a/dhall-nix.cabal b/dhall-nix.cabal
index e7302ec..0b483fa 100644
--- a/dhall-nix.cabal
+++ b/dhall-nix.cabal
@@ -1,5 +1,5 @@
Name: dhall-nix
-Version: 1.1.16
+Version: 1.1.17
Cabal-Version: >=1.10
Build-Type: Simple
Tested-With: GHC == 8.0.1
@@ -30,7 +30,7 @@ Library
base >= 4.11.0.0 && < 5 ,
containers < 0.7 ,
data-fix < 0.4 ,
- dhall >= 1.34 && < 1.35,
+ dhall >= 1.35 && < 1.36,
hnix >= 0.7 && < 0.10,
lens-family-core >= 1.0.0 && < 2.2 ,
neat-interpolation < 0.6 ,
diff --git a/src/Dhall/Nix.hs b/src/Dhall/Nix.hs
index c230fe0..4f84da7 100644
--- a/src/Dhall/Nix.hs
+++ b/src/Dhall/Nix.hs
@@ -4,6 +4,7 @@
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeFamilies #-}
+{-# LANGUAGE ViewPatterns #-}
{-| This library only exports a single `dhallToNix` function for translating a
Dhall syntax tree to a Nix syntax tree for the @hnix@ library
@@ -103,6 +104,7 @@ import Dhall.Core
, Chunks (..)
, DhallDouble (..)
, Expr (..)
+ , FunctionBinding (..)
, MultiLet (..)
, PreferAnnotation (..)
, Var (..)
@@ -236,7 +238,7 @@ dhallToNix e =
-- If any other number, then rename the variable to include the maximum
-- depth.
maximumDepth :: Var -> Expr s Void -> Maybe Int
- maximumDepth v@(V x n) (Lam x' a b)
+ maximumDepth v@(V x n) (Lam FunctionBinding {functionBindingVariable = x', functionBindingAnnotation = a} b)
| x == x' =
max (maximumDepth v a) (fmap (+ 1) (maximumDepth (V x (n + 1)) b))
maximumDepth v@(V x n) (Pi x' a b)
@@ -271,10 +273,10 @@ dhallToNix e =
x' = x <> Data.Text.pack (show n)
renameShadowed :: Expr s Void -> Maybe (Expr s Void)
- renameShadowed (Lam x a b) = do
+ renameShadowed (Lam FunctionBinding { functionBindingVariable = x, functionBindingAnnotation = a} b) = do
(x', b') <- rename (x, b)
- return (Lam x' a b')
+ return (Lam (Dhall.Core.makeFunctionBinding x' a) b')
renameShadowed (Pi x a b) = do
(x', b') <- rename (x, b)
@@ -293,14 +295,14 @@ dhallToNix e =
loop (Const _) = return untranslatable
loop (Var (V a 0)) = return (Fix (NSym a))
loop (Var a ) = Left (CannotReferenceShadowedVariable a)
- loop (Lam a _ c) = do
+ loop (Lam FunctionBinding { functionBindingVariable = a } c) = do
c' <- loop c
return (Fix (NAbs (Param a) c'))
loop (Pi _ _ _) = return untranslatable
-- None needs a type to convert to an Optional
loop (App None _) =
return (Fix (NConstant NNull))
- loop (App (Field (Union kts) k) v) = do
+ loop (App (Field (Union kts) (Dhall.Core.fieldSelectionLabel -> k)) v) = do
v' <- loop v
let e0 = do
k' <- Dhall.Map.keys kts
@@ -593,8 +595,11 @@ dhallToNix e =
c' <- loop c
return (Fix (NBinary NUpdate b' c'))
loop (RecordCompletion a b) =
- loop (Annot (Prefer PreferFromCompletion (Field a "default") b) (Field a "Type"))
- loop (Field (Union kts) k) =
+ loop (Annot (Prefer PreferFromCompletion (Field a def) b) (Field a typ))
+ where
+ def = Dhall.Core.makeFieldSelection "default"
+ typ = Dhall.Core.makeFieldSelection "Type"
+ loop (Field (Union kts) (Dhall.Core.fieldSelectionLabel -> k)) =
case Dhall.Map.lookup k kts of
-- If the selected alternative has an associated payload, then we
-- need introduce the partial application through an extra abstraction
@@ -614,7 +619,7 @@ dhallToNix e =
return (k', Nothing)
let e2 = Fix (NSym k)
return (Fix (NAbs (ParamSet e0 False Nothing) e2))
- loop (Field a b) = do
+ loop (Field a (Dhall.Core.fieldSelectionLabel -> b)) = do
a' <- loop a
return (Fix (NSelect a' [StaticKey b] Nothing))
loop (Project a (Left b)) = do