{-# 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 = forall s a. Binding s a -> Expr s a -> MultiLet s a
multiLet Binding s a
b1 Expr s a
e1
in forall s a. NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
MultiLet (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 -> forall s a. NonEmpty (Binding s a) -> Expr s a -> MultiLet s a
MultiLet (Binding s a
b0 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 = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr 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)