Skip to content

Instantly share code, notes, and snippets.

@eduardoleon
Last active August 29, 2015 14:27
Show Gist options
  • Save eduardoleon/1f233823503f41a5a904 to your computer and use it in GitHub Desktop.
Save eduardoleon/1f233823503f41a5a904 to your computer and use it in GitHub Desktop.
Parentheses generation benchmark: GHCi vs. OCaml vs. Poly/ML
lolcathost% ghci
GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help
> type F a = (a, a)
> type G a = F (F a)
> type H a = G (G a)
> type I a = H (H a)
> type J a = I (I a)
> type K a = J (J a)
> let f :: a -> F a ; f x = (x, x)
> let g :: a -> G a ; g x = f (f x)
> let h :: a -> H a ; h x = g (g x)
> let i :: a -> I a ; i x = h (h x)
> let j :: a -> J a ; j x = i (i x)
> let k :: a -> K a ; k x = j (j x)
C-c C-c^CInterrupted.
lolcathost% eval `opam config env`
lolcathost% ocaml
OCaml version 4.02.3
# type 'a f = 'a * 'a
type 'a g = 'a f f
type 'a h = 'a g g
type 'a i = 'a h h
type 'a j = 'a i i
type 'a k = 'a j j
let f x : 'a f = x, x
let g x : 'a g = f (f x)
let h x : 'a h = g (g x)
let i x : 'a i = h (h x)
let j x : 'a j = i (i x)
let k x : 'a k = j (j x);;
type 'a f = 'a * 'a
type 'a g = 'a f f
type 'a h = 'a g g
type 'a i = 'a h h
type 'a j = 'a i i
type 'a k = 'a j j
val f : 'a -> 'a f = <fun>
val g : 'a -> 'a g = <fun>
val h : 'a -> 'a h = <fun>
val i : 'a -> 'a i = <fun>
val j : 'a -> 'a j = <fun>
val k : 'a -> 'a k = <fun>
# k ();;
- : unit k =
(((((((((((((((((((((((((((((((((), ()), ((), ())), (((), ()), ((), ()))),
((((), ()), ((), ())), (((), ()), ((), ())))),
(((((), ()), ((), ())), (((), ()), ((), ()))),
((((), ()), ((), ())), (((), ()), ((), ()))))),
((((((), ()), ((), ())), (((), ()), ((), ()))),
((((), ()), ((), ())), (((), ()), ((), ())))),
(((((), ()), ((), ())), (((), ()), ((), ()))),
((((), ()), ((), ())), (((), ()), ((), ())))))),
((...), ...)),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...),
...)
#
lolcathost% poly
Poly/ML 5.5.2 Release
> type 'a f = 'a * 'a
# type 'a g = 'a f f
# type 'a h = 'a g g
# type 'a i = 'a h h
# type 'a j = 'a i i
# type 'a k = 'a j j
# fun f x : 'a f = (x, x)
# fun g x : 'a g = f (f x)
# fun h x : 'a h = g (g x)
# fun i x : 'a i = h (h x)
# fun j x : 'a j = i (i x)
# fun k x : 'a k = j (j x);
C-c C-c^CCompilation interrupted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment