<orbitz>
Does anyone know how to get lwt.sytnax working in OcamlMakefile?
<orbitz>
camlp4 is having tourbel ifnding pa_lwt.cmo
ztfw has quit [Remote host closed the connection]
joewilliams is now known as joewilliams_away
joko has joined #ocaml
<joko>
Hello, I am using the Array module to create a two dimensional array and I want to find the sum of every element in this array, with every element being multiplied by a number based on the index.
<joko>
Could you help me define easily the indices involved? I can do two Array.fold_left and get the sum of the elements, but I don't know how to get the index on every fold
<adrien>
Array.iteri?
<joko>
Ah, how I missed that? It's getting late for me, I guess...
<joko>
Thank you very much, adrien
<adrien>
=)
joewilliams_away is now known as joewilliams
<joko>
Hm, how I would use an accumulator in iteri?
<adrien>
you could use a reference instead
<orbitz>
WHy not just implement on otp of fold_left?
<joko>
could you make a small example? newbie here, not sure what you mean...
<orbitz>
val foldi_left : (int -> 'a -> 'b -> 'a) 'a -> 'b array -> 'a
<adrien>
let x = ref 0 in let f i e = some_computation_on_the_index_and_e; incr x in Array.iter f yourarray
<adrien>
(gotta love code like that on one line)
<orbitz>
let foldi_left f init arr = Array.fold_left (fun (i, a) e -> (i + 1, f i a e)) (0, a) init
<orbitz>
let foldi_left f init arr = snd (Array.fold_left (fun (i, a) e -> (i + 1, f i a e)) (0, a) init)
<joko>
Wow, thank you both, orbitz and adrien
<joko>
Nice idea, orbitz
Obfuscate has joined #ocaml
<joko>
I have to read about references, I suppose, to better understand adrien's code
<orbitz>
a reference is jus ta mutable box
<orbitz>
they tend ot be slow in ocaml though
alexyk has joined #ocaml
alexyk has quit [Read error: Connection reset by peer]
alexyk has joined #ocaml
alexyk has quit [Read error: Connection reset by peer]
fabjan_ has quit [Ping timeout: 250 seconds]
fabjan has joined #ocaml
fabjan has quit [Ping timeout: 250 seconds]
munga has quit [Ping timeout: 255 seconds]
fabjan has joined #ocaml
alexyk has joined #ocaml
fabjan has quit [Ping timeout: 250 seconds]
fabjan has joined #ocaml
alexyk has quit [Quit: alexyk]
fabjan has quit [Ping timeout: 240 seconds]
fabjan has joined #ocaml
fabjan has quit [Ping timeout: 250 seconds]
fabjan has joined #ocaml
nox- has quit [Quit: Leaving]
boscop has quit [Ping timeout: 240 seconds]
Amorphous has quit [Ping timeout: 272 seconds]
boscop has joined #ocaml
Amorphous has joined #ocaml
drunK has quit [Remote host closed the connection]
smerz has quit [Quit: Ex-Chat]
jonafan_ has joined #ocaml
jonafan has quit [Ping timeout: 240 seconds]
kerneis has quit [Ping timeout: 260 seconds]
myu2 has joined #ocaml
myu2 has quit [Remote host closed the connection]
myu2 has joined #ocaml
joewilliams is now known as joewilliams_away
almaisan-away is now known as al-maisan
ikaros has joined #ocaml
ulfdoz has quit [Ping timeout: 265 seconds]
ikaros has quit [Quit: Leave the magic to Houdini]
kerneis has joined #ocaml
<al-maisan>
how does one convert a string to an integer? I need to do something like string_to_int("1")
<al-maisan>
int_of_string ?
<flux>
yes :)
<flux>
generally ocaml libraries never use x_to_y, but rather y_of_x
<flux>
also, modules typically can have functions to_x, of_x
<al-maisan>
thanks flux !
seafood has joined #ocaml
seafood has quit [Quit: seafood]
ftrvxmtrx has quit [Quit: Leaving]
myu2 has quit [Remote host closed the connection]
mlh has quit [Ping timeout: 248 seconds]
mlh has joined #ocaml
_andre has joined #ocaml
fraggle_ has quit [Ping timeout: 276 seconds]
kaustuv has joined #ocaml
lamawithonel_ has joined #ocaml
melwtech45 has joined #ocaml
asmanur_ has joined #ocaml
mbac_ has joined #ocaml
lamawithonel has quit [*.net *.split]
asmanur has quit [*.net *.split]
diml has quit [*.net *.split]
mbac has quit [*.net *.split]
melwtech35 has quit [*.net *.split]
diml has joined #ocaml
ftrvxmtrx has joined #ocaml
WonTu has joined #ocaml
WonTu has left #ocaml []
munga has joined #ocaml
mlh has quit [Ping timeout: 248 seconds]
hto has quit [Read error: Connection reset by peer]
hto has joined #ocaml
mlh has joined #ocaml
explodus has joined #ocaml
avsm has joined #ocaml
ski has joined #ocaml
lamawithonel_ has quit [Remote host closed the connection]
<hcarty>
The short version is that "module type of ..." does not work under camlp4
joewilliams_away is now known as joewilliams
mnabil has quit [Ping timeout: 276 seconds]
<hcarty>
camlp5 does support the new syntax. That camlp* split is really unfortunate.
<flux>
indeed
<flux>
should've gone the other way, the naming
<hcarty>
flux: And the internal vs external, from what I've seen regarding upkeep of the two
<flux>
hcarty, internal vs external?
<hcarty>
camlp5 is now external to the main OCaml project, while the new camlp4 is internal
<hcarty>
But camlp5 seems to be more actively maintained.
<flux>
well, I can understand why the inria folk don't want to maintain and "old" version
<flux>
and then that just happens naturally, if someone else is interested in maintaining it
<hcarty>
flux: Indeed. It's just unfortunate that the more actively maintained version is the one which is not part of the core language.
<flux>
I do wonder if at certain point one should just 'let go' of camlp4, but I guess there are still old-camlp4-dependant syntax extensions that haven't been updated
<hcarty>
flux: "let go" of syntax extensions in general?
<flux>
let go of the old version
<flux>
or does camlp5 have some reason for existence other than legacy code?-o
<flux>
coq?-)
<hcarty>
coq is my guess
<hcarty>
I don't personally have any use for camlp5 (over camlp4). I'm just (very very mildly) bitter that I can't use some of the new 3.12 features with camlp4 (new version)
<flux>
well, I see it as a bug..
<flux>
I'm still in 3.11, possibly 3.10 on some hosts :)
<hcarty>
:-)
<flux>
don't go the bleeding edge and you don't have these sorts of problems ;)
<hcarty>
flux: Curses! :-)
<adrien>
well, loooks like 3.13 has incompatible changes to camlp4 so I don't know if we can say one is developped more actively than the other, more like that we see camlp5's announce more maybe
<hcarty>
adrien: That could be. My view of the issue is colored by being bitten by bugs in each release since the 3.10.0 old-camlp4 to new-camlp4 switch.
<hcarty>
adrien: What/where are the incompatible camlp4 changes in 3.13?
<adrien>
yeah, just got bitten by the incompatibility in 3.13
<adrien>
hcarty: dunno but type-conv won't build (haven't tried myself: was julm)
<julm>
File "pa_type_conv.ml", line 350, characters 34-53:
<julm>
Error: Unbound value Gram.token_location
bacam has quit [Read error: Operation timed out]
bacam has joined #ocaml
drunK has joined #ocaml
avsm has joined #ocaml
shm has joined #ocaml
lpereira has joined #ocaml
<kaustuv>
Camlp5 is also used in HOL Light
<f[x]>
and in otags iirc
<kaustuv>
Also, the maintainer of Camlp5 is an INRIAn, just not a Galliumois.
jonafan_ is now known as jonafan
hto has quit [Read error: Connection reset by peer]
<sgnb>
and in matita, ledit, genewb
avsm has quit [Quit: Leaving.]
init1 has joined #ocaml
init1 has quit [Client Quit]
init1 has joined #ocaml
WonTu has joined #ocaml
<hcarty>
I would like to create a module which includes functions which return maps keyed on strings. I would like to use the Map.Make functor, but avoid having the user tied to My_module.My_map. Is a functor the right way to go here, or are there other options?
WonTu has left #ocaml []
<hcarty>
I suppose one option is to use the polymorphic Map module.
mnabil has joined #ocaml
munga has quit [Ping timeout: 264 seconds]
al-maisan is now known as almaisan-away
ftrvxmtrx has quit [Quit: Leaving]
<thelema>
hcarty: polymorphic map is good. in theory you could functorize, with the parameter being a functor itself. but polymorphism seems easier
<thelema>
has anyone else had segfault problems with Pycaml.pytuple_setitem? It seems to fail for me, just trying to set the 0th entry in a newly created tuple
<hcarty>
thelema: My concern with polymorphic map is that it seems difficult to use custom comparison functions
myu2 has quit [Remote host closed the connection]
<hcarty>
Not all entry points allow you to provide one
ulfdoz has joined #ocaml
ygrek has joined #ocaml
avsm has joined #ocaml
_andre has quit [Quit: leaving]
ulfdoz has quit [Ping timeout: 265 seconds]
ulfdoz has joined #ocaml
boscop has quit [Read error: Connection reset by peer]
<al-maisan>
File "equilibrium.ml", line 27, characters 12-14:
<al-maisan>
Error: Syntax error
<al-maisan>
After removing line 26 the source compiles w/o errors
<adrien>
missing ';' at the end of the line
<al-maisan>
adrien: thanks! Why would I need a ';' -- I thought ocaml does not need any?
<adrien>
it usually doesn't because it has 'let ... = ... in'
<adrien>
but when you don't use let in, you need a kind of delimiter
<al-maisan>
so ';' is a delimiter inside blocks of code?
<hcarty>
al-maisan: ";" can be used with imperitive code, when you only care about side effects
<hcarty>
al-maisan: It is an almost-synonym for "let () = ... in"
<al-maisan>
aha, and Print.printf is an example of that -- it produces side effects as opposed to a meaningful return value?
<hcarty>
al-maisan: Yes
<al-maisan>
hcarty, adrien : thank you very much for the explanation!
jm_ocaml has joined #ocaml
<hcarty>
al-maisan: You're welcome, have fun :-)
<al-maisan>
:)
ikaros has joined #ocaml
Submarine has quit [Ping timeout: 260 seconds]
hto has joined #ocaml
Anarchos has joined #ocaml
init1 has quit [Remote host closed the connection]
init1 has joined #ocaml
hto has quit [Quit: Lost terminal]
ygrek has quit [Ping timeout: 245 seconds]
hto has joined #ocaml
ulfdoz has quit [Ping timeout: 276 seconds]
ygrek has joined #ocaml
ikaros has quit [Read error: Connection reset by peer]
opla2 has joined #ocaml
<opla2>
is : type Bla = string * int ... valid syntax?
<opla2>
"type Bla = string * int"
<adrien>
lowercase: "bla"
<opla2>
and can be used as a tuple of : string * int
<opla2>
?
<opla2>
adrian? That is more of convention than anything else right?
ygrek has quit [Ping timeout: 245 seconds]
<adrien>
uppercase first letter is reserved for enum members, I don't know why
<opla2>
adrian : Aha.. well im using F# and there it seems possible
<opla2>
it is possible i mean
<opla2>
for Types atleast..
<opla2>
...just started to learn
hto has quit [Quit: Lost terminal]
Anarchos has quit [Ping timeout: 265 seconds]
hto has joined #ocaml
init1 has quit [Quit: Quitte]
init1 has joined #ocaml
ikaros has joined #ocaml
hto has quit [Quit: Lost terminal]
ikaros_ has joined #ocaml
al-maisan is now known as almaisan-away
<opla2>
isnt 1..4 = [1,2,3,4] ?
<opla2>
or how do i create a list with a range?
ikaros has quit [Ping timeout: 255 seconds]
<adrien>
with "base" ocaml, you can't but Batteries has support for this syntax afaik
<adrien>
I'm not a heavy Batteries user however so I may easily be wrong
<hcarty>
There is no ".." syntax
<hcarty>
But there is a ( -- ) operator
<opla2>
ive seen it in for loops
<hcarty>
And there is syntax for list comprehensions
<opla2>
like : for i in 1..4 do
<adrien>
been doing to much shell script lately =/
<opla2>
...in F# that is though
<hcarty>
opla2: In OCaml, it's "for i = 1 to 10 do"
<opla2>
aha
hto has joined #ocaml
mnabil_ has joined #ocaml
<opla2>
oh.. should be : seq { 1..4 }
lpereira has quit [Quit: Leaving.]
ikaros has joined #ocaml
ikaros_ has quit [Ping timeout: 264 seconds]
munga has joined #ocaml
hto has quit [Quit: Lost terminal]
hto has joined #ocaml
<opla2>
can i create a list of functions with provided argument the same return value and use tryPick until first function returns desired result?
init1 has quit [Quit: Quitte]
hyperboreean has quit [Ping timeout: 265 seconds]
hyperboreean has joined #ocaml
<opla2>
a list of "uninvoked" / "unapplied" functions that dont share name/arguments but have the same option return value
<thelema>
opla2: of course - functions of the same type can be put into a list
<thelema>
I don't know tryPick, though...
<opla2>
but how do i put a function-with-arguments in a list wo applying/invoking the function
<jm_ocaml>
tryPick seems to be part of the f# standard library
<thelema>
jm_ocaml: ok
<thelema>
opla2: just use its name
<thelema>
let values = [incr; decr; (fun r -> r := 0)]
<thelema>
this has type (int ref -> unit) list
<thelema>
you have to have the same type. - different arguments prevents this
<opla2>
only have same return type
<opla2>
some sort of currying but wo the invokation part
<opla2>
sure.. can to : if - else if - ... else if - else
<opla2>
but it feels ugly =D
<thelema>
even in f#, you can't invoke on different types
<thelema>
in batteries, there's find_map, which should do what you want
<jm_ocaml>
at what point do you apply the functions to their argument(s)?
<thelema>
List.find_map
<thelema>
val find_map : ('a -> 'b option) -> 'a list -> 'b
<thelema>
this is the array tryPick function in f#: Array.tryPick : ('T -> 'U option) -> 'T [] -> 'U option
<opla2>
jm_ocaml, in the iteration
<thelema>
opla2: you're iterating across a list/array of things
<thelema>
that list has the same type, so your function has type 'a -> 'b option
mnabil_ has quit [Ping timeout: 240 seconds]
<thelema>
one difference between find_map and tryPick is that find_map raises an exception if the value isn't found.
* thelema
needs to put find_map into BatList.Exceptionless
willb has quit [Ping timeout: 255 seconds]
<opla2>
actually i am sending of list of Unit -> U option to tryPick
<thelema>
okay, you can do that. I guess you want to avoid evaluating all the functions if the first one returne Some x?
<opla2>
yeah
<thelema>
hmm, I have the feeling some monadic construction would do what you want.
<thelema>
But I'm not so good at monads, what about using laziness?
<opla2>
sounds good
myu2 has joined #ocaml
<opla2>
dont get confused by me talking about tryPick.. it is then list api of F# but maybe not ocaml
<opla2>
(last one just a notice)
<thelema>
List.find (fun x -> force x <> None) [lazy (f x y z); lazy (g a b); ...]
<opla2>
nice
<opla2>
thanx
<opla2>
btw.. what is the difference between the syntax of : f x y z and f(x,y,z) ?
<thelema>
find_map would be a bit better - BatList.find_map Lazy.force [lazy (f x y z); lazy(g a b); ...]
<thelema>
the first one returns the lazy thunk, so you'd have to force it and match to get rid of the [Some], while the second would return the value directly.
<jm_ocaml>
why not write it out as let find_some flist = match flist with [] -> None | f::fs -> f()
<thelema>
jm_ocaml: you're missing more in the second case
<opla2>
gotto interpret that..
<opla2>
first week of ocaml/f#
<jm_ocaml>
yes, you're right.
<thelema>
opla2: don't get too fancy, try to work straightforward
<opla2>
thelema.. sure.. but i wanna learn some on my way
<opla2>
thelema, but what does the notation f x y z mean
<opla2>
or jm_ocaml
<jm_ocaml>
it's simply a number of function apllications (((f x) y) z)
<opla2>
aha
<opla2>
in my code i get "The value or constructor f is not defined"
<opla2>
cant it be an instance function
<jm_ocaml>
oh, that list was just an example
<opla2>
yeah sure.. my "f" is named differentlly
<jm_ocaml>
right, I just read what you wrote earlier
<jm_ocaml>
in the first case, f x y z, you have a curried function
<jm_ocaml>
in the second, f (x,y,z), f is a function applied to a triple
<jm_ocaml>
those are not interchangeable notations
<jm_ocaml>
to give a more specific example, compare the following to functions:
<jm_ocaml>
let f x y = x + y
<jm_ocaml>
and
<jm_ocaml>
let f (x,y) = x + y
<jm_ocaml>
the first allows partial application
<jm_ocaml>
you can write f x and obtain a function of type int -> int
<jm_ocaml>
makes sense?
<thelema>
the first f is a function with two arguments, the second has one argument (that being a 2-tuple)
<opla2>
okey i get it
<opla2>
so we would have wo lazy ?
melwtech45 is now known as melwtech35
<opla2>
giving an element function as
<thelema>
no, lazy is still the best way to put the functions into a list, unless you want to add a () parameter to each function
<thelema>
i.e. instead of [let f x y = ...], [let f x y () = ...]
<opla2>
oh okey.. so they actually get invoked once all arguments are given
<opla2>
fun x -> x
<opla2>
..in the loop that is
<opla2>
if x had type: () -> U option
jonafan has quit [Quit: Leaving]
<jm_ocaml>
that is indeed the case ;)
myu2 has quit [Remote host closed the connection]
<thelema>
it's possible to have a function that does some work with each argument, but not common.
<thelema>
the syntax for that is let f = fun x -> do work with x; fun y -> do work with x and y; fun z -> stuff with x, y, z