Created
March 12, 2019 17:31
-
-
Save dreverri/c1679f1fd6a6a17d595d56483d43fc90 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Recursive Person example from https://github.com/dhall-lang/dhall-lang/wiki/How-to-translate-recursive-code-to-Dhall | |
-- Modified to work in a similar way to https://github.com/dhall-lang/dhall-lang/tree/gabriel/json_pure_dhall/Prelude/JSON | |
let Person = | |
∀(Person : Type) | |
→ ∀(mk : { name: Text, children: List Person } → Person) | |
→ Person | |
let map = https://prelude.dhall-lang.org/List/map | |
let makePerson = | |
λ(name : Text) | |
→ λ(children: List Person) | |
→ λ(Person: Type) | |
→ λ(mk : { name : Text, children : List Person } → Person) | |
→ mk { name = name, children = | |
( map | |
Person@1 | |
Person | |
(\(c: Person@1) -> c Person mk) | |
children | |
) | |
} | |
let concatSep = https://prelude.dhall-lang.org/Text/concatSep | |
let render = | |
λ(x : Person) | |
→ x | |
Text | |
(λ(p : { name : Text, children : List Text }) | |
→ concatSep ", " ([ p.name ] # p.children) | |
) | |
let a = makePerson "a" ([] : List Person) | |
let b = makePerson "b" ([] : List Person) | |
let c = makePerson "c" [a, b] | |
in render c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment