|
List Info
Thread: "ocaml_beginners"::[] Easy Vector Graphics from OCaml
|
|
| "ocaml_beginners"::[] Easy
Vector Graphics from OCaml |
  United Kingdom |
2007-05-29 03:21:14 |
|
We just released our vector graphics library with both free and commercial
editions:
http://www.ffconsultancy.com/products/smoke_vector_graphics/?o
This library lets you create stunning interactive vector graphics quickly and
easily from OCaml programs.
The site contains three downloadable demos for Linux (both 32- and 64-bit) and
the library is freely available for non-commercial use in the form of
compiled bytecode for OCaml 3.09.2.
Happy hacking!
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
The F#.NET Journal
http://www.ffconsultancy.com/products/fsharp_journal/?e
__._,_.___
.
__,_._,___
|
| "ocaml_beginners"::[] why does
this recursion not work? |
  United States |
2007-05-31 15:05:27 |
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
I forget what this kind of recursion is called and I cannot seem to get it to
work.
Here is an (failing) example for a function that counts how many times it has
been called with an even argument:
let numeven b =
let rec aux a b =
(a, aux (if b mod 2 = 0 then a + 1 else a))
in aux 0
It errors with: This expression has type int * (int -> int * 'a) but is here
used with type int * 'a
I know I can write a side-effecting version using a hidden ref, but I need a
functional version. Does any one know how do you do this in OCaml and what
is this type of thing is called?
Thanks in advance,
Peng
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.2 (GNU/Linux)
iD8DBQFGXyqNfIRcEFL/JewRAi6tAKCGYWYM3gxP44ofacLs35ECGOtjygCfa164
wQA03R/o1moyivgmC06yJY0=
=N9JN
-----END PGP SIGNATURE-----
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] why
does this recursion not work? |
  United States |
2007-05-31 15:26:42 |
|
On May 31, 2007, at 4:05 PM, Peng Zang wrote:
>
> let numeven b =
> let rec aux a b =
> (a, aux (if b mod 2 = 0 then a + 1 else a))
> in aux 0
>
You're only applying aux to one argument (both times). Did you mean:
let numeven b =
let rec aux a b =
aux a (if b mod 2 = 0 then + 1 else a)
in
aux 0 b
--Jonathan
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] why
does this recursion not work? |
  United States |
2007-05-31 15:47:37 |
|
Hi, not sure what you are trying to do, but if you want to be
side-effects free, you can carry the state with you in each
invocation, like:
# open Printf ;;
# let multiply_and_count state number =
let n_state = if number mod 2 = 0 then state +1 else state in
n_state, number * 2;;
val multiply_and_count : int -> int -> int * int = <fun>
# let st,r = multiply_and_count 0 3;;
val st : int = 0
val r : int = 6
# let st2, r2 = multiply_and_count st 4;;
val st2 : int = 1
val r2 : int = 8
2007/5/31, Jonathan Bryant < jtbryant%40valdosta.edu">jtbryant valdosta.edu>:
>
> On May 31, 2007, at 4:05 PM, Peng Zang wrote:
> >
> > let numeven b =
> > let rec aux a b =
> > (a, aux (if b mod 2 = 0 then a + 1 else a))
> > in aux 0
> >
>
> You're only applying aux to one argument (both times). Did you mean:
>
> let numeven b =
> let rec aux a b =
> aux a (if b mod 2 = 0 then + 1 else a)
> in
> aux 0 b
>
> --Jonathan
>
>
--
Pablo Polvorin
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] why
does this recursion not work? |
  United States |
2007-05-31 15:35:48 |
|
On May 31, 2007, at 4:05 PM, Peng Zang wrote:
>
> Here is an (failing) example for a function that counts how many
> times it has
> been called with an even argument:
>
Sorry, didn't read that part: I jumped ahead to the error message.
You could use some sort of continuation, but a ref would be much easier.
--Jonathan
__._,_.___
.
__,_._,___
|
| Re: "ocaml_beginners"::[] Re:
why does this recursion not work? |
  United States |
2007-06-01 18:42:35 |
|
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Ha! You're brilliant. That's exactly what I wanted. I didn't know you had
to explictly enable recursive types. Why isn't this enabled by default?
Slow compile times?? Safety?
Peng
On Thursday 31 May 2007 17:24, Zheng Li wrote:
> Peng Zang < peng.zang%40gmail.com">peng.zang gmail.com> writes:
> > -----BEGIN PGP SIGNED MESSAGE-----
> > Hash: SHA1
> >
> > I forget what this kind of recursion is called and I cannot seem to get
> > it to work.
> >
> > Here is an (failing) example for a function that counts how many times it
> > has been called with an even argument:
> >
> > let numeven b =
> > let rec aux a b =
> > (a, aux (if b mod 2 = 0 then a + 1 else a))
> > in aux 0
> >
> > It errors with: This expression has type int * (int -> int * 'a) but is
> > here used with type int * 'a
> >
> > I know I can write a side-effecting version using a hidden ref, but I
> > need a functional version. Does any one know how do you do this in OCaml
> > and what is this type of thing is called?
>
> Enable recursive type, if that's what you really want.
>
> $ ocaml -rectypes
> Objective Caml version 3.09.2
>
> # let numeven b =
> let rec aux a b =
> (a, aux (if b mod 2 = 0 then a + 1 else a)) in
> aux 0;;
> val numeven : 'a -> (int -> int * 'b as 'b) = <fun>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.2 (GNU/Linux)
iD8DBQFGYK7tfIRcEFL/JewRArD1AJ9KXg3JuUNKI3HIEUF8u0Qcae5QLgCgvuYy
ndGX5GanftdcCcBvTKv2k+4=
=jH1x
-----END PGP SIGNATURE-----
__._,_.___
.
__,_._,___
|
[1-6]
|
|