Skip to content

Instantly share code, notes, and snippets.

@niuk
Created July 5, 2011 22:48
Show Gist options
  • Select an option

  • Save niuk/1066137 to your computer and use it in GitHub Desktop.

Select an option

Save niuk/1066137 to your computer and use it in GitHub Desktop.
interface Eq require
{type T; eq}
interface Eq provide
type T : Type
eq : (T, T) -> Bool
module EqInt : Eq where
type T = Int
eq = builtIn_eqInt
interface Cmp require
module C : Eq
lt : (T, T) -> Bool
interface Cmp default
type T = C.T
type Result =
$lesser $equal $greater
cmp(x, y) =
if C.eq(x, y)
then $equal
else
if lt(x, y)
then $lesser
else $greater
interface Cmp provide
{type T; type Result; cmp}
module CmpInt : Cmp where
module C = EqInt
lt = builtIn_ltInt
@niuk
Copy link
Author

niuk commented Jul 6, 2011

So apparently combining ML's module system with Haskell's typeclasses yields the equivalent of Java's interfaces and classes, minus inheritance. Go to https://github.com/Nenmin/Nail/blob/master/syntax to see what I mean.

@md2perpe
Copy link

md2perpe commented Jul 7, 2011

I'll have a closer look at Nail.

After getting in contact with my "old" Haskell teacher, I was reminded that O'Haskell had turned into Timber.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment