From: Michael <michipili@gmail.com>
To: caml-list@inria.fr
Subject: [Caml-list] Writing Awk in OCaml
Date: Sun, 28 Jul 2013 10:43:12 +0200 [thread overview]
Message-ID: <B3FE1B71-74DC-4674-BFE2-7A44186E527D@gmail.com> (raw)
Hi list!
I am trying to write a Awk in OCaml and would like to write it as a
variadic function. I have seen several examples of variadic functions
in OCaml, but I am still unsure if it is possible. Maybe can someone
help me to solve this?
DEFINITION OF (MINI)-AWK
(Mini)-Awk is a module with the following (probably wrong) signature:
sig
type 'a field
type row = string array
val make : int -> (string -> 'a) -> 'a field
val get : 'a field -> row -> 'a
val bind : (row -> 'a -> 'b) -> 'a field -> row -> 'b
end
With this signature [make 1 int_of_string] if a field [f] such that
[get f row = int_of_string (row.(1))].
Now assume you have two fields f1 : int field and f2 : string field
and two functions u : int -> state -> state and v : int -> string ->
state -> state (where state is a random type).
With the above signature, we can write (1)
bind u f1: row -> state -> stat
bind (bind v f1) f2 : row -> state -> stat
But it would be quite nice to be able to write the following
expressions so that they are defined and correctly type (2):
bind u f1 : row -> state -> state
bind v f1 f2 : row -> state -> state
Is there any way to rewrite things so that the cumbersome (1) can be
replaced by the slick (2) ?
Thank you for your insight!
Michael
next reply other threads:[~2013-07-28 8:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-28 8:43 Michael [this message]
2013-07-29 12:40 ` Xavier Leroy
2013-07-30 17:57 ` Michael
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=B3FE1B71-74DC-4674-BFE2-7A44186E527D@gmail.com \
--to=michipili@gmail.com \
--cc=caml-list@inria.fr \
/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