<c0m>
just having a little hard time reading functional syntax too
<c0m>
i'm doing in f#
<c0m>
i think my algorithm is right just i don't know how to correctly program it
<c0m>
i stripped it down here
<c0m>
let rec gencut(n, xs) = if n = 0 then [] else List.hd xs :: gencut (n-1, List.tl xs);;
<c0m>
for gencut(3, [9; 8; 7; 6; 5; 4; 3; 2; 1]);; ... it returns [9; 8; 7]
<c0m>
seems to be on right track
<c0m>
but i want to return a nested list
<c0m>
any clues?
<c0m>
trying to make that code return a nested list
<julm>
what that would be in your example ?
<c0m>
i typed the example
<c0m>
and what it returned based on my algorith
<c0m>
m
<julm>
yes, but the nested list you want, what that would be in your example ?
<c0m>
well for gencut(3, [9; 8; 7; 6; 5; 4; 3; 2; 1]);; ... it should really return [[9; 8; 7], [6;5;4;3;2;1]]
<c0m>
but right now my algorithm returns [9;8;7]
<c0m>
so to start slow, i just want to return that in a nested list
<c0m>
so [[9;8;7]]
<c0m>
but i can't figure out the syntax
<julm>
[[9; 8; 7], [6;5;4;3;2;1]] is (int list * int list) list
<julm>
not : int list list
<c0m>
how does that differ from
<c0m>
([9; 8; 7], [6;5;4;3;2;1])
<julm>
([9; 8; 7], [6;5;4;3;2;1]) is: int list * int list
<julm>
note that you're using , not ;
<c0m>
what is that exactly
<c0m>
maybe that is why i am having trouble with types
<julm>
, is for tuples
<c0m>
i don't fully understand
<julm>
; for lists
<c0m>
ok so .... int * int ... is a tuple of two ints?
<julm>
yep
<c0m>
ok
<julm>
is you cut your list in two you only need a tuple of two lists, not a list of lists
<julm>
-is+if
<c0m>
yes
<c0m>
i think i just understood that now
<c0m>
so i'm trying to determine hwo to create a typle
<julm>
(x, y)
<julm>
(x, y, z)
<c0m>
List.hd xs, List.tl xs gives error
<c0m>
btw, thank you for helping me and your time
<julm>
List.hd xs, List.tl xs should work, what is around ?
<c0m>
let rec gencut(n, xs) = if n = 0 then [] else if n = 1 then List.hd xs, List.tl xs else List.hd xs :: gencut (n-1, List.tl xs);;
<julm>
but () around
<julm>
put*
<c0m>
tried that
<c0m>
(List.hd xs, List.tl xs) .. right?
<julm>
yep
<julm>
but also you have to return a tuple for each case
<julm>
when n=0 too
<c0m>
ah
<julm>
and in else also
<c0m>
so ([])
<julm>
([], xs)
<c0m>
bah
<c0m>
expecting a' list but given a' list list
<julm>
code please
<c0m>
let rec gencut(n, xs) = if n = 0 then ([], xs) else if n = 1 then (List.hd xs, List.tl xs) else (List.hd xs :: gencut (n-1, List.tl xs), []);;
<c0m>
for the else
<c0m>
btw i'm sorry for the newbie questions
<julm>
let rec gencut(n, xs) =
<julm>
if n = 0 then ([], xs)
<julm>
else let ns, zs = gencut (n-1, List.tl xs)
<julm>
in (List.hd xs :: ns, zs);;
<julm>
but this way of doing things may harm because it is not tail-recursive; see my pastebin version for a tail-rec version
<c0m>
what was wrong with the way i was trying?
<julm>
when you recursively call gencut it is not a jump, it is a sub-routine call; which means it push a return adress on the stack, and thus make the stack growing
<julm>
pushes*
<julm>
address*
<julm>
makes*
<c0m>
also do you mind explaining yours to me real quick?
<c0m>
specifically the in part
<julm>
let (x, y) = f z in just binds x and y from a 2-tuple returned by f
<c0m>
thought it was something like that
<julm>
it is this need of doing the recursive call in a let/in that makes the function not tail-rec
<c0m>
oh
<c0m>
yours
<c0m>
yes i saw that
<c0m>
i thought you were talking about mine
<c0m>
and was getting confused
<c0m>
for the way i was doing it what was wrong with that?
<julm>
you didn't deconstruct the tuple returned by gencut
<julm>
you did (List.hd xs :: gencut (n-1, List.tl xs), [])
<julm>
which does not typecheck by the way, since gencut does not return the list needed at the right of ::
<julm>
and there you see the second element of the tuple should not be []
<c0m>
right
<julm>
so you must deconstruct the tuple returned by gencut, which is what I've done with let ns, zs = gencut (n-1, List.tl xs) in
<c0m>
but i was planning on when n = 1 that it would return the correct part
<julm>
the case n=1 is not necessary, it is corretly handled by the else case
<c0m>
hmm
<c0m>
let ns, zs = gencut(n - 1, List.tl xs) in (List.hd xs::ns, zs)
<c0m>
that binds gencut call to ns
<c0m>
and the (list.hd xs::ns, zs) to zs ?
<c0m>
what does in do
<julm>
nono
<julm>
let tup = gencut (n-1, List.tl xs) in let (ns, zs) = tup in (List.hd xs :: ns, zs);;
<julm>
write it this way if you prefer
<c0m>
man i've been programming for like 10 years, never done functional
<c0m>
i mean i can pick stuff up here and there but jsut some things i'm not getting
<c0m>
so even your new way i don't get
<c0m>
sorry to waste your time :(
<julm>
let x = y in is just like let x = y ;; but [in] does not end the function
<julm>
let x = y in (...) means x will be bind to y with-in (...)
<julm>
here y is gencut blabla
<julm>
whith is a tuple
<julm>
so we write x as a 2-tuple
<julm>
and that gives us (ns, zs)
<c0m>
hmm ok
<c0m>
let me read slowly
<c0m>
i've been working for 14 hours
<orbitz>
c0m: new to pattern matching?
<c0m>
nope
<c0m>
i understand that
thrasibule has quit [Read error: 110 (Connection timed out)]
f[x] has joined #ocaml
verte has quit ["~~~ Crash in JIT!"]
mjonsson has quit [Read error: 110 (Connection timed out)]
Alpounet has quit ["Leaving"]
Yoric[DT] has joined #ocaml
Yoric[DT] has quit ["Ex-Chat"]
mal`` has quit ["Coyote finally caught me"]
mal`` has joined #ocaml
kattla has joined #ocaml
albacker has joined #ocaml
nnyby is now known as ItsWellAfterEigh
_zack has joined #ocaml
Alpounet has joined #ocaml
Alpounet has quit [Remote closed the connection]
Alpounet has joined #ocaml
kaustuv_` has joined #ocaml
verte has joined #ocaml
Alpounet has quit [Remote closed the connection]
Alpounet has joined #ocaml
onigiri_ has joined #ocaml
onigiri has quit [Read error: 110 (Connection timed out)]
onigiri_ is now known as onigiri
kaustuv_ has quit [Read error: 110 (Connection timed out)]
Alpounet has quit [Remote closed the connection]
Alpounet has joined #ocaml
Snark has joined #ocaml
Anarchos has joined #ocaml
ikaros has joined #ocaml
ItsWellAfterEigh is now known as PlzDonLie
PlzDonLie is now known as PlzDonLie2Me
Narrenschiff has joined #ocaml
nimred_ has quit [robinson.freenode.net irc.freenode.net]
tab_ has quit [robinson.freenode.net irc.freenode.net]
det has quit [robinson.freenode.net irc.freenode.net]
ertai_ has quit [robinson.freenode.net irc.freenode.net]
_zack has quit ["Leaving."]
nimred_ has joined #ocaml
tab_ has joined #ocaml
det has joined #ocaml
ertai_ has joined #ocaml
ikaros_ has joined #ocaml
PlzDonLie2Me is now known as SillyStuff
ikaros has quit [Read error: 110 (Connection timed out)]
Anarchos has quit ["Vision[0.9.7-H-090423]: i've been blurred!"]
f[x] has quit [Read error: 145 (Connection timed out)]
Narrenschiff has quit []
ikaros_ has quit ["Leave the magic to Houdini"]
<flux>
so, at some point, has syntax {foo "bar" with a = 42} become invalid?
<flux>
because I have 3.08 software here which uses that, and I need to rewrite that to {(foo "bar") with..
<flux>
also, apparently previously it's been possible to apply functors with function application like syntax, without parens..
ikaros has joined #ocaml
<kaustuv_`>
flux: {(foo "bar") with a = 42}
<flux>
kaustuv_`, yes, and that's exactly the rewriting I needed to do with this piece of software
<kaustuv_`>
ah, right, missed your second message
<flux>
another is that it used loads of curried functor applications
kaustuv_` is now known as kaustuv
<kaustuv>
Functors are still curreid as far as I know
<kaustuv>
Foo(String)(Printf)(Gc)
NYNix has joined #ocaml
<flux>
yes, but not as: Foo String Printf Gc
<flux>
because the source was filled with those
<kaustuv>
Was the source in revised syntax?
<flux>
not that I noticed
<kaustuv>
Well, there were a bunch of syntax changes in 3.09, and even more in 3.10
<flux>
no, it's not
<flux>
(not revised)
<flux>
in any case, lfs doesn't seem to work..
<kaustuv>
there was someone asking about LFS just a few days back.
<Camarade_Tux>
lfs?
<flux>
logic file system
<flux>
allows some forms of tagging and queries per file size and boolean expressions etc
<flux>
uses fuse as its interface
<flux>
however, the last time I tried it it just segfaulted when I did something
<Camarade_Tux>
oh, I see :)
smimou has joined #ocaml
<flux>
this time it doesn't just appear to do anything useful, the mountpoint is not connected according to the kernel
<Camarade_Tux>
several fuse-based filesystems don't work
<Camarade_Tux>
actually, most don't
<flux>
hey, now at the second try it does something
<flux>
camarade_tux, really?
<flux>
or just the ocaml ones :P
<kaustuv>
fuse is (was?) not a stable API
<flux>
readme.txt's last line: Nevertheless, relaunch and pray and at some times it should work (that works for me at least)
<flux>
(it blamed berkeley db, though, as it apparently works with gdbm)
<Camarade_Tux>
many are unmaintained, use libs that don't work...
<flux>
apparently the software is under GPL even though it originates from inria, perhaps I'll be able to submit patch for 3.10 :-o
<kaustuv>
inria has no problem with the GPL as such
<kaustuv>
I think the guy who worked on LFS/LIS etc. is an INRIA guy
<Camarade_Tux>
hmmm, yeah, I think I remember that
<Camarade_Tux>
hop, parti
<Camarade_Tux>
crap, I pressed enter before Alt+left ><
<julm>
hahaha :P
* Camarade_Tux
is a bit sleepy ;)
<kaustuv>
a tough nuit blanche?
<Camarade_Tux>
not really, I hadn't planned I'd be in Paris and I didn't know it was that night, plus it's always overcrowded =/
<Camarade_Tux>
but 4am nonetheless and a weird week ;)
<flux>
bah, now I have something in the lfs directory (mkdir fails as file exists) but nothing is visible
<flux>
I suppose it's not very practical or safe for real use
<kaustuv>
unless you need to get rid of some data
<flux>
well yes..
<flux>
actually I wasn't thinking I'd risk my data on that at all, just put symbolic links in - not sure if it supports that, though
f[x] has joined #ocaml
<flux>
even a command-line 'tag foo *.txt' would work for me, something that'd maintain a hidden directory and would have size/inode-based recovery in case files get moved outside the ystem
animist has quit [Read error: 110 (Connection timed out)]
ikaros has quit ["Leave the magic to Houdini"]
_zack has joined #ocaml
ulfdoz has quit [Read error: 110 (Connection timed out)]
Narrenschiff has joined #ocaml
Ched has joined #ocaml
ched_ has quit [Read error: 113 (No route to host)]
verte has quit ["~~~ Crash in JIT!"]
^authentic has joined #ocaml
authentic has quit [Read error: 110 (Connection timed out)]
<Camarade_Tux>
unfortunately I don't have time to really read it properly now
sramsay has quit [Read error: 104 (Connection reset by peer)]
julm_ has joined #ocaml
julm has quit [Read error: 104 (Connection reset by peer)]
ttamttam1 has joined #ocaml
<flux>
camarade_tux, about the url rewriter usage of ganame: I doubt it'd work :). but ganame would be relatively easy to patch for such use.
<Camarade_Tux>
flux: plenty of time left, I still have to actually start caravel ;-)
<Camarade_Tux>
(I'm a bit stuck in ocaml-gir, waiting for help=
ikaros has joined #ocaml
ttamttam has quit [Read error: 110 (Connection timed out)]
bzzbzz has joined #ocaml
julm has joined #ocaml
julm_ has quit [Read error: 104 (Connection reset by peer)]
NYNix has joined #ocaml
<NYNix>
je
<NYNix>
typo, sorry
Yoric[DT] has joined #ocaml
Submarine has joined #ocaml
kaustuv_ has joined #ocaml
NYNix has quit [Read error: 145 (Connection timed out)]
julm_ has joined #ocaml
julm has quit [Read error: 145 (Connection timed out)]
kaustuv has quit [Read error: 110 (Connection timed out)]
NYNix has joined #ocaml
SillyStuff is now known as nnyby
Snark has quit [Read error: 148 (No route to host)]
julm has joined #ocaml
julm_ has quit [Read error: 104 (Connection reset by peer)]
albacker has quit ["Leaving"]
NYNix has quit [Read error: 105 (No buffer space available)]
_zack has quit ["Leaving."]
<hcarty>
Camarade_Tux: This is a day or several late, but (Quick_plot.lines [(xs0, ys0); (xs1, ys1); ...];) would give you a plot of xsN vs ysN using OCaml + PLplot :-)
<hcarty>
Camarade_Tux: You would have to do the work to get xs0 and ys0 as float arrays, of course.
NYNix has joined #ocaml
<Alpounet>
hcarty, can't it just guess what we want to plot ?
<Alpounet>
:-p
julm has quit [Read error: 54 (Connection reset by peer)]
f[x] has quit [Read error: 145 (Connection timed out)]
<hcarty>
Alpounet: That's something to look forward to with the combo of OCaml 4.0.0 and PLplot 6.0.0 :-)
<Alpounet>
haha :p
julm has joined #ocaml
NYNix has quit [Read error: 60 (Operation timed out)]
Narrenschiff has joined #ocaml
ttamttam1 has quit ["Leaving."]
Submarine has quit [Client Quit]
Narrenschiff has quit []
sramsay_ has quit [Read error: 110 (Connection timed out)]
<Camarade_Tux>
I second Alpounet, it should guess what we want ;p
Yoric[DT] has quit ["Ex-Chat"]
onigiri has joined #ocaml
valross has joined #ocaml
Smerdyakov has quit ["Leaving"]
smimou has quit ["bli"]
Mr_Awesome has joined #ocaml
mjonsson has joined #ocaml
myst has left #ocaml []
tvn2009 has quit [Remote closed the connection]
<thelema_>
Camarade_Tux: I'll get to work on the DWIM module (Do What I Mean)
<Camarade_Tux>
thelema_: thanks a million \o/
<Camarade_Tux>
otoh, it'd require clear and precise thinking, not sure I can do that :D
<Alpounet>
it'll have to guess what's the best for you for moments when you can't think of it yourself
<Camarade_Tux>
do you think DWIM could write DWIM?
<flux>
val dwim : unit -> 'a
<flux>
and it'd work every time!
<Camarade_Tux>
he :P
<Camarade_Tux>
well, time to go to bed, good night :)
<flux>
good night
<Alpounet>
gn
<flux>
(I'm actually woke up at night, so I too will soon be back to the bed)
<Alpounet>
let fix f = let x = f x in x in fix dwim ;;
<hcarty>
let f () = failwith "dwim";;
<hcarty>
It's unit -> 'a at least...
<Alpounet>
why should it be ?
<Alpounet>
except because flux told so
<Alpounet>
:-p
tmaedaZ is now known as tmaeda
<flux>
actually I think the proper prototype would be val dwim : 'a -> 'b
<hcarty>
flux: So the stigma associated with Obj.magic is a conspiracy.
<flux>
hcarty, yes.. indeed Obj.magic can sometimes fit the "do what I mean"-bill. but. not always..
<flux>
hcarty, I think Obj.magic is more likely "do what I think I mean, and if I don't know what I mean, crash in surprising and spectacular ways"
<flux>
so, Obj.dwitimaiidkwimcisasw?
<flux>
(maybe if it was called that way, people would use it less)
<hcarty>
flux: That seems to be quite a nice description
<hcarty>
And a fantastic rename.
<flux>
for batteries maybe?
<Alpounet>
agreed :p
<hcarty>
Seconded!
<hcarty>
Thirded. Whichever is appropriate.
* Alpounet
remembers some crashes in his very early OCaml days.
<Alpounet>
People expect great things from something with "magic" in its name... A typical human reaction.
<hcarty>
I've definitely hit some segfaults when working in OCaml, but they have all been due to issues with C.