gusl: (Default)
[personal profile] gusl
Does Haskell or ML support code like the following?


>> a : p;
a : p

>> b : q;
b : q

>> c : p -> q -> r;
c : p -> q -> r

>> d = (c a);
d : q -> r

>> f : r -> s;
f : r -> s

>> e = lambda(x) (f(d x));
e : q -> s


Note that I get these inferences even though the variables were not instantiated, and the functions were not implemented.

(no subject)

Date: 2008-10-17 10:13 pm (UTC)
From: [identity profile] simrob.livejournal.com
You could do it in ML by declaring a signature STUFF and then using a functor that expects a module of type STUFF.

signature STUFF = sig
type p
type q
type r

val a : p
val b : q
val c : p -> q -> r
val d : q -> r
val f : r -> s
end

functor Funct(X: STUFF) = struct
open X
val e : fn x => f(d x)
end

(no subject)

Date: 2008-10-17 10:14 pm (UTC)
From: [identity profile] simrob.livejournal.com
That last one should have been val e = fn x => f(d x) - I'm sure there were other errors too :)

(no subject)

Date: 2008-10-17 10:29 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
after I enter STUFF, do I need ";;"? If so, then I get an error: "Unbound constructor STUFF".

(no subject)

Date: 2008-10-17 10:47 pm (UTC)
From: [identity profile] simrob.livejournal.com
Okay, let's do this right:

signature STUFF = sig
type p
type q
type r
type s

val a : p
val b : q
val c : p -> q -> r
val d : q -> r
val f : r -> s
end

functor Funct(X: STUFF) = struct
open X
val e = fn x => f(d x)
end;;


If you put that into the REPL loop you should get what you're looking for. Or you can put it, without the ;;, into "foo.sml" and then say use "foo.sml";; from inside the REPL loop. This is SML, not OCaml, by the way.

(no subject)

Date: 2008-10-17 10:50 pm (UTC)
From: [identity profile] gustavolacerda.livejournal.com
I only have OCaml. Does this become a lot different?

(no subject)

Date: 2008-10-17 11:02 pm (UTC)
From: [identity profile] roseandsigil.livejournal.com
module type STUFF = sig
type p
type q
type r
type s

val a : p
val b : q
val c : p -> q -> r
val d : q -> r
val f : r -> s
end

module Funct(X: STUFF) = struct
include X
let e = fun x -> f(d x)
end;;

(no subject)

Date: 2008-10-18 10:03 am (UTC)
From: [identity profile] gustavolacerda.livejournal.com
Thanks! That works!

if I now want to instantiate/implement some of these variables/functions, would I use the constructor STUFF, passing in p,q,r,etc? What if I only want to instantiate some of them?

(no subject)

Date: 2008-10-18 01:48 am (UTC)
ikeepaleopard: (Default)
From: [personal profile] ikeepaleopard
If you don't want to deal with modules, you can give non-terminating terms or exception raising terms any type you want e.g.

let a = (raise Fail) : p

(no subject)

Date: 2008-10-18 08:33 pm (UTC)
From: [identity profile] simrob.livejournal.com
Also true. Can't really do that inside the REPL loop, though.

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags