Skip to content

Instantly share code, notes, and snippets.

@niuk
Created July 5, 2011 22:48
Show Gist options
  • Save niuk/1066137 to your computer and use it in GitHub Desktop.
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
@md2perpe
Copy link

md2perpe commented Jul 6, 2011

What language?

@niuk
Copy link
Author

niuk commented Jul 6, 2011

A hypothetical language that currently exists only in my head.

@md2perpe
Copy link

md2perpe commented Jul 6, 2011

Okey. I love that (i.e. people having ideas about languages)!

@niuk
Copy link
Author

niuk commented Jul 6, 2011

I think I have come up with an improved formulation of the same concepts.

@md2perpe
Copy link

md2perpe commented Jul 6, 2011

Have you taken ideas from Haskell? Your interfaces Eq and Cmp are very similar to Haskell's classes Eq and Ord.

@niuk
Copy link
Author

niuk commented Jul 6, 2011

Haskell is my favorite programming language, and I deliberately try to emulate it when designing this language. Interfaces are basically Haskell typeclasses, and classes are instances, except named and parameterized.

@md2perpe
Copy link

md2perpe commented Jul 6, 2011

Haskell is my favorite language, too, although it's not suitable all the time. I work as a PHP programmer.

Have you looked at exensions like O'Haskell (or Haskell++) and Cayenne?

@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