<Stalkr_>
bitbckt: Error: This expression has type float
<Stalkr_>
This is not a function; it cannot be applied.
<Stalkr_>
Sorry, it has another signature. Thanks
lewis1711 has joined #ocaml
<bitbckt>
:)
<lewis1711>
how do define something like map, that I can reference the previous element with?
<jyc>
What would the previous element be for the first element?
<lewis1711>
yeah you've got me there
<lewis1711>
it's basically a normal map, with a function that returns a tuple of ('a, int)
<lewis1711>
but int may or not be incremeneted
<lewis1711>
so I want to reference the int value of the previous element
<lewis1711>
it's easy to do imperatively,, but I thought I'd try and be functional
<bitbckt>
if the tuple is 'a option, you can fold with a None seed.
<bitbckt>
uhm. to be clear: ('a option, int) :)
<lewis1711>
hmmm, no it's not
<bitbckt>
I presume you'd make it so, then unwrap as necessary in the result.
<pierpa>
you do it with a fold_left
<bitbckt>
^^
<lewis1711>
but then I'd have to reverse it in the end
<pierpa>
life's hard :)
<bitbckt>
or you get more creative with your fold state.
<lewis1711>
I think I'm just a really lazy functional programmer. if I am zipping maps together, fine. when I have to have creative fold state.. what's the point again? :p
<bitbckt>
whatever flips your skirt up *shrug*
<lewis1711>
anyway I'll lookup a map from fold_left
<pierpa>
can you map2 on the list and a shifted version of the same list?
<pierpa>
map2 (fun a prev -> ...) list (foo::list)
<lewis1711>
where foo is the int value. hmm
<lewis1711>
init value, rather
<pierpa>
excep that the two lists must be same length :(
<lewis1711>
oh right
<lewis1711>
mapi!
<pierpa>
that would be quadratic?
<pierpa>
(if you want to use i to nth the list, that is)
<lewis1711>
yeah hmm
<lewis1711>
I could do it explicitly with pattern matching
<pierpa>
you could write a function map_prev which exactly what you need
<pierpa>
*does
<xyh>
is there a way to load a file to REPL without it prints type back for me ?
<xyh>
for 'no truncate on bytes' makes the REPL useless to me ...
<Drup>
sure, just compile the file to a cmo (or a cma) and use that
madroach has quit [Ping timeout: 246 seconds]
psy_ has quit [Ping timeout: 265 seconds]
madroach has joined #ocaml
d0nn1e has quit [Ping timeout: 255 seconds]
Stalkr_ has quit [Quit: Leaving...]
kakadu has quit [Remote host closed the connection]
d0nn1e has joined #ocaml
demonimin has quit [Ping timeout: 245 seconds]
<lewis1711>
what's the idiomatic thing to call an inner recursive function for some other function f?
<lewis1711>
just "let rec inner_f" ?
<lyxia>
let rec f' is nice
<lyxia>
let rec f too
<lyxia>
unless the toplevel function you're defining is already recursive of course
aantron has quit [Remote host closed the connection]
mac10688 has quit [Read error: Connection reset by peer]
<xyh>
if I have a function body like
<xyh>
fun () -> <part1>; <part2>; ;;
<xyh>
is it true that <part1> is executed first, then <part2>
<lyxia>
when that function is applied yes
<xyh>
but I have a function,
<xyh>
when I comment out <part2>, <part1> prints something,
<xyh>
but when I add <part2> back it stops printing things (and running into a infi-loop)!
<xyh>
how is this happens ?
<lyxia>
it's probably something to do with buffering
<lyxia>
xyh: try print_newline inbetween both parts
<xyh>
oh!
<xyh>
thank you lyxia, that was scary.
lokien_ has quit [Quit: Connection closed for inactivity]
FreeBirdLjj has joined #ocaml
<pierpa>
is there a way to rewrite this function in a less clunky way: let a_key table = try Hashtbl.iter (fun k v -> raise (Key k)) table; (0, 0) with Key k -> k;; ?
<pierpa>
sgnb` has joined #ocaml
<pierpa>
for example, what if I want it to be polymorphic? this one works only for (int * int) keys
sgnb has quit [Ping timeout: 250 seconds]
<xyh>
lyxia: is this kind of buffering is about IO ?
<lyxia>
pierpa: put the key in a reference and return an option instead of a default value
<lyxia>
xyh: what do you mean?
<xyh>
how buffering influences sequenced function calls ?
<pierpa>
lyxia: you mean something like: let a_key table =
<pierpa>
let k0 = ref (0,0) in
<pierpa>
(try Hashtbl.iter (fun k v -> k0 := k; raise Exit) table
<pierpa>
with Exit -> ());
<pierpa>
!k0;;
<pierpa>
<pierpa>
still I don't know how to make it polymorphic
<def`>
Then maybe you can try "Modern compiler in ML" from Appel. The book is using SML, but once you know OCaml it is really easy to translete.
<wagle>
wanting to hack on the ocaml and coq sources
<def`>
wagle: then real world OCaml is a good choice
<def`>
it is really about OCaml. not an introduction to programming
<wagle>
interesting, forgot about appel's book
<def`>
not that compilation is a broad subject.
<def`>
note*
<def`>
Appel is more about code generation.
<def`>
IF you want to study frontend and type systems, TAPL is the answer
<def`>
(And TAPL uses OCaml in its examples)
<wagle>
ok.. getting real close to finally reading TAPL
<pierpa>
xyh: kinda like a forth interpreter?
<xyh>
pierpa: yes it is, see the README :)
<pierpa>
looking now :)
<pierpa>
good job :)
<wagle>
anyone know the difference between the 1st and 2nd editions of Appel's compiler book (seems to be only java)
<pierpa>
there are version in SML, C, and Java, AFAIK
<pierpa>
ah, you mean, 2nd ed is only Java?
<wagle>
yeah, as far as I can tell
<pierpa>
then no, I don't know :)
<wagle>
ahaha
<pierpa>
anyway, if the difference was important, it would have been well pubblicized and would be easy to find. If you can't find informations it means there's no important difference
<pierpa>
beware that every recensions I have read warn that the non-SML versions suck
<wagle>
ok, thanks all
<wagle>
i just now ordered rwo
<wagle>
(rwoc?)
<pierpa>
usually is RWO
<pierpa>
(I have always seen it mentioned as RWO)
<xyh>
oh! you do not found that my ocaml code formating is very very bad ?
<pierpa>
btw, do you know that RWO is available also on the net for free?
<pierpa>
xyh: yes, your formatting is different than usual
<wagle>
yeah, but rreading abook is easier for me
<pierpa>
ok, just to be sure you knew :)
<wagle>
plus i can mark it up
<xyh>
what does RWO denote ?
<pierpa>
of course, a book is better
<pierpa>
Real World Ocaml
<wagle>
(i'm currently looking at the web version)
<pierpa>
k
struk|desk2 is now known as struk|desk|away
xm_ has quit [Ping timeout: 252 seconds]
contempt has quit [Disconnected by services]
contempt has joined #ocaml
mac10688 has joined #ocaml
struk|desk|away is now known as struk|desk2
xyh has quit [Remote host closed the connection]
mahasamoot has quit [Remote host closed the connection]
xyh has joined #ocaml
mac10688 has quit [Ping timeout: 240 seconds]
johnelse has quit [Ping timeout: 264 seconds]
struk|desk2 is now known as struk|desk|away
johnelse has joined #ocaml
johnelse is now known as Guest5963
tmtwd has joined #ocaml
ygrek has quit [Ping timeout: 264 seconds]
MercurialAlchemi has joined #ocaml
darkf_ has joined #ocaml
darkf_ is now known as darkf
JacobEdelman has quit [Quit: Connection closed for inactivity]
pierpa has quit [Ping timeout: 272 seconds]
MercurialAlchemi has quit [Ping timeout: 245 seconds]
tmtwd has quit [Ping timeout: 245 seconds]
djellemah_ is now known as djellemah
<lewis1711>
I feel like Option.value should really take a thunk for its default arg
lokien_ has joined #ocaml
pyon has joined #ocaml
jacquev6 has joined #ocaml
<flux>
really? I guess by thunk you mean a lazy value or a function?
<lewis1711>
yeah
<lewis1711>
() -> 'a
<flux>
wouldn't it be better to use 'a Option.t Lazy.t?
<lewis1711>
hmm, dunno about this lazy t
<lewis1711>
basically my default value had a side effect. prob an edge case, and I was wrong
maker has quit [Ping timeout: 244 seconds]
jacquev6 has quit [Quit: jacquev6]
jacquev6 has joined #ocaml
maker has joined #ocaml
jacquev6 has quit [Client Quit]
jacquev6 has joined #ocaml
antkong_ has quit [Quit: antkong_]
Haudegen has quit [Ping timeout: 256 seconds]
iorivur has quit [Ping timeout: 250 seconds]
iorivur has joined #ocaml
Haudegen has joined #ocaml
iorivur has quit [Ping timeout: 276 seconds]
octachron has joined #ocaml
iorivur has joined #ocaml
sgnb` is now known as sgnb
antkong has joined #ocaml
nicoo has quit [Ping timeout: 245 seconds]
sepp2k has joined #ocaml
demonimin has joined #ocaml
antkong has quit [Read error: Connection reset by peer]
iorivur has quit [Ping timeout: 245 seconds]
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
nicoo has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
FreeBirdLjj has joined #ocaml
lewis1711 has quit [Ping timeout: 264 seconds]
sigjuice has quit [Ping timeout: 264 seconds]
bitbckt has quit [Ping timeout: 260 seconds]
bitbckt has joined #ocaml
iorivur has joined #ocaml
sigjuice has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
luz1e is now known as luzie
FreeBirdLjj has joined #ocaml
larhat2 has quit [Quit: Leaving.]
Simn has joined #ocaml
mort___ has joined #ocaml
Sorella has quit [Quit: Connection closed for inactivity]
jwatzman|work has joined #ocaml
_andre has joined #ocaml
kushal has quit [Quit: Leaving]
antkong has joined #ocaml
luzie has left #ocaml [#ocaml]
kushal has joined #ocaml
xyh has quit [Quit: ChatZilla 0.9.92 [SeaMonkey 2.39/20151206235742]]
kakadu has joined #ocaml
d0nn1e has quit [Ping timeout: 260 seconds]
d0nn1e has joined #ocaml
Stalkr_ has joined #ocaml
hannes` is now known as hannes
rand has joined #ocaml
rand is now known as Guest47640
Guest47640 has quit [Quit: leaving]
demonimin has quit [Ping timeout: 260 seconds]
jacquev6 has left #ocaml [#ocaml]
Haudegen has quit [Ping timeout: 276 seconds]
antkong has quit [Quit: antkong]
nicoo has quit [Remote host closed the connection]
iorivur has quit [Ping timeout: 245 seconds]
nicoo has joined #ocaml
freehck has joined #ocaml
iorivur has joined #ocaml
xyh has joined #ocaml
xyh_ has joined #ocaml
Haudegen has joined #ocaml
yomimono has joined #ocaml
contempt has quit [Remote host closed the connection]
Stalkr_ has quit [Ping timeout: 264 seconds]
xyh has quit [Remote host closed the connection]
xyh has joined #ocaml
JacobEdelman has joined #ocaml
lewis1711 has joined #ocaml
zpe has joined #ocaml
dario1 has joined #ocaml
BitPuffin has joined #ocaml
ontologiae has joined #ocaml
Sorella has joined #ocaml
FreeBirdLjj has quit [Remote host closed the connection]
mort___ has quit [Ping timeout: 240 seconds]
iorivur has quit [Ping timeout: 272 seconds]
tmtwd has joined #ocaml
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
tmtwd has quit [Ping timeout: 240 seconds]
zpe has quit [Ping timeout: 246 seconds]
<Leonidas>
wagle: yeah, wasn't a fan of appels compiler book in java ;-)
JacobEdelman has quit [Quit: Connection closed for inactivity]
<lewis1711>
I like java. really like discriminated unions though. and no, the visitor pattern is not the same. I can define a DU without refering what will use it
kushal has quit [Quit: Leaving]
kdas_ has joined #ocaml
kdas_ has quit [Remote host closed the connection]
kdas_ has joined #ocaml
kdas_ is now known as kushal
kushal has quit [Changing host]
kushal has joined #ocaml
Guest5963 is now known as johnelse
lokien_ has quit [Quit: Connection closed for inactivity]
<Stalkr_>
Any good resources on OCaml AST rewriting? For example (+ x 0) -> x
<def`>
do you want 1. to do rewriting on an Ocaml file? 2. to know how constant folding is implemented in Ocaml compiler? 3. to do rewriting on your own language implemented in OCaml?
<Stalkr_>
#3, trying to write my own little language
<def`>
hmm, I don't have particular recommandation
<def`>
for simple cases, pattern matching will do
<Stalkr_>
Is it easiest to just write a rec function or should it be done when parsing?
<def`>
oh, never during parsing
<def`>
keep passes as separate as possible
<def`>
it leads to cleaner & simpler code
<def`>
and will be much easier to debug
<def`>
there are principled way to implement generic traversal, but in the end it is often easier to just implemebt your own adhoc routine
<def`>
a good tradeoff is a function mapping one level of ast nodes
<Stalkr_>
So maybe split it up into multiple functions that will deal with different matches? First rewrite operands, then strings, then whatever. Say (* "hello" 3) -> (join "" "hello" "hello" "hello") for strings, then I pass it like: ast -> operands -> strings -> new_ast
xyh has quit [Quit: ChatZilla 0.9.92 [SeaMonkey 2.39/20151206235742]]
zpe has joined #ocaml
t4nk108 has joined #ocaml
mort___ has quit [Ping timeout: 250 seconds]
zpe has quit [Ping timeout: 250 seconds]
t4nk108 has quit [Client Quit]
jacquev6 has quit [Quit: jacquev6]
jacquev6 has joined #ocaml
kushal has quit [Ping timeout: 264 seconds]
kushal has joined #ocaml
lokien_ has quit [Quit: Connection closed for inactivity]
ygrek has joined #ocaml
psy_ has quit [Read error: No route to host]
<Drup>
aantron: your kstream.ml is weird :p
<aantron>
Drup: oh yes? :)
Stalkr_ has quit [Quit: Leaving...]
MercurialAlchemi has quit [Remote host closed the connection]
MercurialAlchemi has joined #ocaml
<Drup>
yeah, it looks like you hardcoded all the little pieces you needed directly into it, which is not wrong, just make it look a bit weird :p
<Drup>
(and I'm not convinced by the "continuation but one-shot" design, too)
<Drup>
anyway, very cool to see you working on that :)
<aantron>
which little pieces do you mean? you mean kstream and stream_io into markup.ml?
<Algebr>
what is the kstream for? the html parser?
<aantron>
its how the whole library is composed. char stream -> unicode stream -> token stream -> signal stream, for both parsers
<Drup>
kstream's implementation itself
jacquev6 has quit [Quit: jacquev6]
<aantron>
im not sure what you mean. but i would be very happy to use an external library. as it is now i am looking to either factor kstream out (probably under some better name :) ) or be educated on what is a better choice :)
<aantron>
it would also be nice to have a good lazy persistent sequence for lambda soup, that stuff doesnt belong in its api either
<Drup>
the choice is simple, really
<Drup>
if you want to iterate bits by bits, you use gen
<Drup>
if you want to walk through the iterator in one go, you use sequence
<Drup>
(I'm really curious what you mean by "straightforward concept of composition" though)
xyh has joined #ocaml
<aantron>
i just meant something wrapped in a stream, instead of a state type with variant types telling you when to feed it more values to get more output. it wasnt a well-formed thought. i just know i wouldnt want to write a parser that consisted out of 4 such machines connected in sequence
<aantron>
so lets take gen. what if a value will be available, but later (asynchronously)?
<Drup>
cc companion_cube ^
zpe has joined #ocaml
<companion_cube>
you mean the value requires IO?
<aantron>
yes basically
<companion_cube>
if you use Lwt or a similar monad, then indeed gen is not well-suited
<companion_cube>
if you use blocking IO then it's fine
<aantron>
in my case i want to support both with a natural interface for each, i decided a stream based on CPS is the join (or meet?) point
<Drup>
companion_cube: didn't you had a solution for that ?
<companion_cube>
Drup: for lwt? I don't think so
<Drup>
weird, I remember so
<companion_cube>
well the 'a gen type doesn't give you room for a monad
ely-se has quit [Quit: Leaving...]
<Drup>
hum
<companion_cube>
then, of course, you could functorize gen over a monad, and use the trivial monad to recover the default behavior
<companion_cube>
with inlining it probably amounts to the same
<companion_cube>
(flambda-grade inlining, that is)
<aantron>
thats what i do
<aantron>
Markup is the trivial monad plus monad-agnostic functions, Markup_lwt is functorized over Lwt
<aantron>
Markup is functorized over*
<aantron>
is the result of i mean.. bah you get it :)
<aantron>
companion_cube: what did you mean by "really need a place to do so"?
<companion_cube>
to discuss iterators properly
<aantron>
like mailing list, IRC channel? forum?
<Drup>
companion_cube: the last discussion didn't turn out very useful, tbh
<companion_cube>
Drup: I know
<Drup>
everyone want's ot NIH in his corner
<aantron>
is there a link to this?
<aantron>
NIH?
<aantron>
not invented here?
<companion_cube>
yes
jacquev6 has joined #ocaml
<Drup>
no link, it was a bunch of emails between various people
<companion_cube>
it really shoudl have been on a public mailing list -_-
<Drup>
companion_cube: as long as there is no answer to "how do I use lwt with {gen, sequence}", the issue is going to stay, I think
<aantron>
why not just the ocaml list?
<companion_cube>
Drup: as long as Bünzli doesn't have his own library, anyway
<Drup>
aantron: the ocaml equivalent of petty politics
<Drup>
companion_cube: but the reason I gave is actually valid
<companion_cube>
maybe we should indeed way for effects and then just ditch Lwt and be happy forever
<companion_cube>
with lwt, use Lwt_stream, that's it
<Drup>
blah
<companion_cube>
s/way/wait/
<companion_cube>
oh wait, gen + delimcc should work :]
jacquev6 has quit [Client Quit]
<Drup>
I stop considering something usable as soon as delimcc pop's up
<Drup>
It's basically a wildcard for "don't do this, or implement it completely differently"
<companion_cube>
:D
<Drup>
(remark valid even when it's oleg using it)
<companion_cube>
oh well
<Drup>
anyway
<Drup>
aantron: I don't care about streaming since I want to use your thing with tyxml with static files <3
<aantron>
Drup: file "blahblah" |> parse_html :p
<Drup>
exactly
<aantron>
but i care about it because someone else may want to "lwt_stream s |> parse_html" and its just as easy :)
<Drup>
oh, you should care :p
<companion_cube>
well I can try to write a monadic Gen, to see how it compares with this :p
Guest24913 has quit [Ping timeout: 264 seconds]
<Drup>
Gen.Make(M: Monad) : S ? :)
<aantron>
meantime i can factor out kstreams. CPS should be adaptable to almost anything
<companion_cube>
Drup: well yes
<aantron>
reading the effects proposal for now
<companion_cube>
let's do it
<companion_cube>
ls
<companion_cube>
gah
<companion_cube>
I can clean up gen in the movement
<aantron>
i also need a persistent sequence type. still thinking about that. persistent lazy asynchronous
<Drup>
gen has a persistent mode
<companion_cube>
well, hmm, gen is somehow persistent if you want it to :>
jacquev6 has joined #ocaml
<aantron>
i experimented with replacing the lambda soup 'a nodes type with a more traditional lazy sequence and got a nice performance hit, because 'a nodes principal elimination form is fold, while a traditional sequence gives you head/tail
<aantron>
i guess some optimization is necessary
kdas_ has joined #ocaml
<Drup>
aantron: you mean, with ocaml's Lazy ?
<aantron>
Drup: i mean where?
<Drup>
"traditional lazy sequence" ?
darkf has quit [Quit: Leaving]
<aantron>
i mean the fundamental destruction operation on a "normal" lazy sequence is some kind of next that gives you head and tail
kushal has quit [Ping timeout: 272 seconds]
<Drup>
that's for lists
<Drup>
not really for all the sequence/iterators stuff
<aantron>
i was under the impression that this is the case for typical lazy persistent sequences
<aantron>
you get the next element and some kind of generator representing the tail
<aantron>
anyway, with regard to sequence, it doesnt seem to support asynchronous programming well either. this is from glancing at the API again
jacquev6 has quit [Quit: jacquev6]
<Drup>
companion_cube: still wondering if we shouldn't have done sequence based on fold instead of iter
<companion_cube>
well the problem, for me, is that you can't without dropping the structural type
<Drup>
you can't ?
<companion_cube>
no, there is a universal type parameter
<Drup>
just take a fold function instead of an iter one
<Drup>
ah, yeah
<Drup>
:/
<companion_cube>
type 'a sequence = forall b. (b -> 'a -> b) -> b -> b
<companion_cube>
I know
<companion_cube>
otherwise I would have done this
Denommus has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
<companion_cube>
and that still doesn't solve the issue of monads
<edwin>
how efficient is Lwt's Lwt_mvar? although I guess thats technically the 'ref' solution you were refering to earlier (generator puts stuff into mvar, and your printing function consumes from there)
octachron has quit [Quit: Leaving]
ely-se has joined #ocaml
govg_ has quit [Quit: leaving]
govg has joined #ocaml
ril has joined #ocaml
slash^ has quit [Read error: Connection reset by peer]
dario1 has quit [Quit: Konversation terminated!]
Algebr has quit [Ping timeout: 240 seconds]
j0sh has quit [Ping timeout: 272 seconds]
kalzz has joined #ocaml
Algebr has joined #ocaml
Algebr is now known as Guest69959
pierpa has joined #ocaml
antkong has quit [Quit: antkong]
j0sh has joined #ocaml
rand has joined #ocaml
rand is now known as Guest33083
sz0 has joined #ocaml
<aantron>
companion_cube: what were the points of difference in past debates on sequences?
<companion_cube>
I think it boiled down to different expectations and priorities
<companion_cube>
some people wanted to maximize the performance, other wanted something general, etc.
MercurialAlchemi has quit [Ping timeout: 256 seconds]
<aantron>
okay
jacquev6 has quit [Quit: jacquev6]
<companion_cube>
also Bünzli decided that it was useless trying to decide anything before effects landed, because it would change the tradeoffs