{-# LANGUAGE LambdaCase #-}
module Dhall.Syntax.MultiLet
( MultiLet(..)
, multiLet
, wrapInLets
) where
import Data.List.NonEmpty (NonEmpty (..))
import Dhall.Syntax.Binding (Binding)
import Dhall.Syntax.Expr (Expr (..))
import qualified Data.List.NonEmpty as NonEmpty
multiLet :: Binding s a -> Expr s a -> MultiLet s a
multiLet :: forall s a. Binding s a -> Expr s a -> MultiLet s a
multiLet Binding s a
b0 = \case
Let Binding s a
b1 Expr s a
e1 ->
let MultiLet NonEmpty (Binding s a)
bs Expr s a
e = Binding s a -> Expr s a -> MultiLet s a
forall s a. Binding s a -> Expr s a -> MultiLet s a
multiLet Binding s a
b1 Expr s a
e1
in NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
forall s a. NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
MultiLet (Binding s a -> NonEmpty (Binding s a) -> NonEmpty (Binding s a)
forall a. a -> NonEmpty a -> NonEmpty a
NonEmpty.cons Binding s a
b0 NonEmpty (Binding s a)
bs) Expr s a
e
Expr s a
e -> NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
forall s a. NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
MultiLet (Binding s a
b0 Binding s a -> [Binding s a] -> NonEmpty (Binding s a)
forall a. a -> [a] -> NonEmpty a
:| []) Expr s a
e
wrapInLets :: Foldable f => f (Binding s a) -> Expr s a -> Expr s a
wrapInLets :: forall (f :: * -> *) s a.
Foldable f =>
f (Binding s a) -> Expr s a -> Expr s a
wrapInLets f (Binding s a)
bs Expr s a
e = (Binding s a -> Expr s a -> Expr s a)
-> Expr s a -> f (Binding s a) -> Expr s a
forall a b. (a -> b -> b) -> b -> f a -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Binding s a -> Expr s a -> Expr s a
forall s a. Binding s a -> Expr s a -> Expr s a
Let Expr s a
e f (Binding s a)
bs
data MultiLet s a = MultiLet (NonEmpty (Binding s a)) (Expr s a)