From: Chris Hecker <checker@d6.com>
To: qrczak@knm.org.pl (Marcin 'Qrczak' Kowalczyk), caml-list@inria.fr
Subject: Re: [Caml-list] dynamically loading C functions
Date: Mon, 05 Mar 2001 16:10:56 -0800 [thread overview]
Message-ID: <4.3.2.7.2.20010305155358.00e26850@shell16.ba.best.com> (raw)
In-Reply-To: <slrn9a80vk.nqi.qrczak@qrnik.zagroda>
>You can provide combinators to build the type information:
Wow, that's pretty cool. I'm not that familiar with abstract types and modules in caml (or any functional language), so this was kind of an eye opener. I think I understand how they work a bit more now, thanks. I do have one thing I can't figure out. Here's my test module:
module C:
sig
type 'a t
val int_t : int t
val float_t : float t
(* Begins with @ so it's right-associative :-) *)
val (@->) : 'a t -> 'b t -> ('a -> 'b) t
val get_function : string -> 'a t -> 'a
val conv : 'a t -> int list
end =
struct
type 'a t = T of int | Tl of int list
let int_t = T 1
let float_t = T 2
let (@->) a b = match a,b with
(T a,T b) -> Tl [a;b]
| (T a,Tl b) -> Tl (a :: b)
| (Tl a,Tl b) -> Tl (a @ b)
| (Tl a,T b) -> Tl (a @ [b])
let get_function s l = Obj.magic s (* just get it to compile *)
let conv (Tl a) = a
end
The way I've done 'a t is as a variant int list. This works, but my @-> flattens nested lists because of the pattern match, so while the type system differentiates between
# (float_t @-> int_t @-> float_t @-> float_t @-> int_t);;
- : (float -> int -> float -> float -> int) C.t = <abstr>
and (note the nested parens):
# (float_t @-> (int_t @-> float_t @-> float_t) @-> int_t);;
- : (float -> (int -> float -> float) -> int) C.t = <abstr>
my internal representation doesn't:
# conv (float_t @-> int_t @-> float_t @-> float_t @-> int_t);;
- : int list = [2; 1; 2; 2; 1]
# conv (float_t @-> (int_t @-> float_t @-> float_t) @-> int_t);;
- : int list = [2; 1; 2; 2; 1]
I thought I could fix this by saying type 'a t = T of int | Tl of 'a t list, but that seems to constrain (@->) to be 'a t -> 'a t -> 'a t and I lose the cruicial ('a -> 'b) t combinator (not sure if I'm using that word correctly) and I get a type error. Any idea how I could get it to nest?
Chris
-------------------
To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-03-06 0:16 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-03-05 20:28 Chris Hecker
2001-03-05 21:24 ` Marcin 'Qrczak' Kowalczyk
2001-03-06 0:10 ` Chris Hecker [this message]
2001-03-06 0:55 ` Chris Hecker
2001-03-06 16:48 ` Marcin 'Qrczak' Kowalczyk
2001-03-06 18:02 ` Chris Hecker
2001-03-08 8:22 ` Fabrice Le Fessant
2001-03-08 9:34 ` Chris Hecker
2001-03-09 10:54 ` Fabrice Le Fessant
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4.3.2.7.2.20010305155358.00e26850@shell16.ba.best.com \
--to=checker@d6.com \
--cc=caml-list@inria.fr \
--cc=qrczak@knm.org.pl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).