Skip to content
This repository has been archived by the owner on Oct 18, 2021. It is now read-only.

Commit

Permalink
Increase prelude usage in the examples
Browse files Browse the repository at this point in the history
Just try to clean up our examples a little bits so they use prelude
functions instead of rolling their own.
  • Loading branch information
SquidDev committed Jan 21, 2020
1 parent 96ccb2e commit 08f7d5a
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 1 addition & 3 deletions examples/amulet-logo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
See `assets/logo.svg' or `assets/logo.png' for an example of the output *)

open import "prelude.ml"

let map = (<$>)
external val float_of_int : int -> float = "function(x) return x end"
open import { lua = "lua/conversion.ml" }

module Math =
include import "lua/math.ml"
Expand Down
8 changes: 4 additions & 4 deletions examples/church-lists.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
external val print : string -> unit = "print"
open import "prelude.ml"

type church 'a = ChurchList of forall 'r. ('a -> 'r -> 'r) -> 'r -> 'r

Expand All @@ -7,7 +7,7 @@ let unList (ChurchList l) = l
let cons x xs = ChurchList (fun k z -> k x (unList xs k z))
and nil = ChurchList (fun _ z -> z)

let printList l =
unList l (fun x k () -> print x; k ()) (fun _ -> print "nil") ()
instance show 'a => show (church 'a)
let show l = unList l (fun x k () -> show x ^ " :: " ^ k ()) (fun _ -> "nil") ()

let main = printList (cons "foo" (cons "bar" nil))
let () = print (cons 1 (cons 2 nil))
4 changes: 1 addition & 3 deletions examples/gadt/term.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
external val ( * ) : int -> int -> int = "function(a, b) return a * b end"
open import "prelude.ml"

type term 'a =
| Lit : int -> term int
Expand All @@ -12,8 +12,6 @@ let rec eval (x : term 'a) : 'a =
| Fun x -> x
| App (f, x) -> (eval f) (eval x)

external val print : 'a -> unit = "print"

let mul a b = App (App (Fun (fun x y -> x * y), a), b)

let () = eval (App (Fun print, mul (Lit 123) (Lit 2)))

0 comments on commit 08f7d5a

Please sign in to comment.