ollehar has quit [Read error: Connection reset by peer]
kdef has quit [Quit: Leaving]
ollehar has joined #ocaml
lordkryss has quit [Quit: Connection closed for inactivity]
badon has joined #ocaml
AltGr has joined #ocaml
javamonn has joined #ocaml
keen_______ has quit [Read error: Connection reset by peer]
javamonn has quit [Remote host closed the connection]
Algebr has quit [Read error: Connection reset by peer]
keen_______ has joined #ocaml
ousado has quit [Ping timeout: 244 seconds]
wraithm has joined #ocaml
swgillespie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
wraithm has quit [Quit: leaving]
javamonn has joined #ocaml
ygrek has quit [Ping timeout: 265 seconds]
ousado has joined #ocaml
ousado has quit [Changing host]
ousado has joined #ocaml
asQuirreL has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
claudiuc has quit [Ping timeout: 245 seconds]
rwmjones has quit [Read error: Connection reset by peer]
rwmjones has joined #ocaml
Nijikokun_ has joined #ocaml
Nijikokun has quit [Ping timeout: 244 seconds]
Nijikokun_ has quit [Ping timeout: 245 seconds]
Nijikokun has joined #ocaml
jamesllondon has quit [Read error: Connection reset by peer]
jamesllondon has joined #ocaml
<destrius_>
i'm noticing what seems to me to be unusual behaviour in List.slice: List.slice [1;2;3] 0 0 --> [1;2;3]
<destrius_>
is there a reason why that returns the full list instead of an empty list?
swgillespie has joined #ocaml
c74d3 is now known as c74d
<yminsky>
List.slice is a confusing function.
<yminsky>
Probably we should remove it from the API.
<yminsky>
It's meant to be python-style slicing. So by doing List.slice[1;2;3] 0 (-1) you'll get [1;2]. And List.slice [1;2;3] (-2) 0 will give you [2;3].
<yminsky>
But I agree it's confusing.
<yminsky>
take, drop and sub are clearer.
javamonn has quit [Read error: Connection reset by peer]
javamonn has joined #ocaml
small-wolf has joined #ocaml
dubosec has joined #ocaml
<dubosec>
this might be too complicated of a question, but I am trying to create a command line version of a simple craps game in ocaml, and I know that read_line lets the user input a string (bytes, actually). Is there some way to take the bytes that the user inputs--such as "roll"--to trigger another function?
<dubosec>
ideally, the user typing "roll" will trigger the random number generator
Nijikokun has quit [Ping timeout: 245 seconds]
<apache2>
pattern matching?
<dubosec>
I mean, I imagine I could do something like "let roll_state = read_line ();;
<dubosec>
but that only creates a value for roll_state; it doesn't make anything happen
<dubosec>
can a conditional check the value of a variable, like roll_state, or am I going about it the wrong way?
sigjuice has joined #ocaml
<Drup>
as apache2 said, pattern matching.
<apache2>
match read_line () with "roll\n" -> bla () | "othercommand\n" -> foo ()
<apache2>
for example
<dubosec>
ah, I understand
<dubosec>
thanks guys, I appreciate it
<apache2>
np
darkf has joined #ocaml
<dmbaturin>
dubosec: There are also guarded patterns. match foo with <pattern> when <condition> -> ...
<dubosec>
there is more of an etiquette question, but is it okay to ask for help with writing programs here, or is this more for asking generic ocaml questions?
<dmbaturin>
If etiquette questions could have boolean answers, the world would be a very different place.
<dubosec>
ha, true. Well, are you okay with questions about writing specific programs/
<dmbaturin>
My opinion is that asking for help with writing programs is fine as long as you don't ask to write the program for you.
MrScout has quit [Ping timeout: 245 seconds]
<Drup>
dubosec: personally, I prefer not to answer other people's course assignments ;)
<dubosec>
that makes since. I'm not in school, so no worries about course assignments from me :)
<dubosec>
seeing it written out now, the pattern matching makes a lot of sense
<dmbaturin>
In every ambiguous situation use pattern matching.
<dmbaturin>
Actually, it's very pervasive. Even a let binding is always a pattern matching.
fraggle-boate_ has joined #ocaml
MrScout has joined #ocaml
tg has quit [Ping timeout: 272 seconds]
<destrius_>
yminsky: ah ok, seems like .sub will do what i need. thanks!
fraggle-boate has quit [Ping timeout: 264 seconds]
<destrius_>
yminsky: anyway i think it can be useful to emulate python's slicing, but the function doesn't really do so faithfully at the moment which adds to the confusion
tg has joined #ocaml
<yminsky>
Indeed.
<apache2>
dubosec: you can also use "if ... else ... then" in ocaml, but pattern matching is usually easier to read/maintain, and ocaml pattern matching uses a subset of ocaml that can be optimized by the compiler
MrScout has quit [Remote host closed the connection]
small-wolf has quit [Ping timeout: 240 seconds]
n3ss3s has joined #ocaml
idegen has quit [Quit: Leaving.]
dubosec has quit [Quit: Leaving]
<n3ss3s>
Successfully rubberducked. Thanks #ocaml
osa1 has quit [Ping timeout: 245 seconds]
<n3ss3s>
(problem solved before pressing enter :p)
contempt has quit [Ping timeout: 252 seconds]
contempt has joined #ocaml
<struktured>
noice
javamonn has quit [Remote host closed the connection]
swgillespie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
struktured has joined #ocaml
MrScout has quit [Read error: Connection reset by peer]
MrScout has joined #ocaml
A1977494 has joined #ocaml
A1977494 has left #ocaml [#ocaml]
MrScout has quit [Ping timeout: 245 seconds]
MrScout_ has joined #ocaml
sdothum has quit [Quit: ZNC - 1.6.0 - http://znc.in]
mengu has joined #ocaml
mengu has joined #ocaml
mengu has quit [Changing host]
<n3ss3s>
oh gawd
<n3ss3s>
I just discovered the whole printf/type safety/format6 spaghetti
mengu has quit [Ping timeout: 264 seconds]
MrScout_ has quit [Ping timeout: 245 seconds]
ygrek has joined #ocaml
<n3ss3s>
Ugh. I want to use sprintf to replace things in a URL, which contains some %'s. sprintf is picking up some of the hexcodes (%3A for example) as "Bad conversion %A". What would you suggest as the most sane way to go about this?
badon has quit [Ping timeout: 252 seconds]
<n3ss3s>
Should I just split the URL at the points where I want to insert stuff, and concatenate?
badon has joined #ocaml
MercurialAlchemi has joined #ocaml
<flux>
n3ss3s, replace each % in the string literal with %%
<n3ss3s>
will the result of sprintf still have single %'s?
<flux>
yes
<n3ss3s>
sweet. let me try
<n3ss3s>
yup. thanks
<n3ss3s>
flux: So it worked in utop, but ocamlopt gives a very unsavory error
Submarine has quit [Remote host closed the connection]
jonludlam has quit [Ping timeout: 264 seconds]
ggole has joined #ocaml
dav has quit [Ping timeout: 256 seconds]
Gama11 has joined #ocaml
dav has joined #ocaml
dsheets has quit [Ping timeout: 272 seconds]
oscar_toro has quit [Ping timeout: 265 seconds]
jyc has quit [Ping timeout: 256 seconds]
thomasga has joined #ocaml
jyc has joined #ocaml
thomasga has quit [Quit: Leaving.]
mengu__ has quit [Ping timeout: 250 seconds]
dsheets has joined #ocaml
thomasga has joined #ocaml
dsheets has quit [Ping timeout: 264 seconds]
testcocoon has quit [Ping timeout: 246 seconds]
aubergines has joined #ocaml
testcocoon has joined #ocaml
oscar_toro has joined #ocaml
thomasga has quit [Quit: Leaving.]
milosn has quit [Ping timeout: 255 seconds]
lordkryss has joined #ocaml
axiles has joined #ocaml
m____ has joined #ocaml
asQuirreL has joined #ocaml
dav has quit [Ping timeout: 256 seconds]
dav has joined #ocaml
Gama11 has quit [Read error: Connection reset by peer]
A1977494 has joined #ocaml
mort___ has joined #ocaml
AltGr has left #ocaml [#ocaml]
A1977494 has left #ocaml [#ocaml]
jonludlam has joined #ocaml
Kakadu has joined #ocaml
thomasga has joined #ocaml
dsheets has joined #ocaml
bjorkintosh has joined #ocaml
Haudegen has quit [Ping timeout: 256 seconds]
rand000 has joined #ocaml
Haudegen has joined #ocaml
milosn has joined #ocaml
milosn has quit [Read error: Connection reset by peer]
TheLemonMan has joined #ocaml
milosn has joined #ocaml
thomasga has quit [Quit: Leaving.]
milosn has quit [Read error: Connection reset by peer]
milosn has joined #ocaml
thomasga has joined #ocaml
sdothum has joined #ocaml
<Leonidas>
lets see if whitequark reacts to bug reports
c74d has quit [Ping timeout: 276 seconds]
struktured has joined #ocaml
milosn has quit [Read error: Connection reset by peer]
milosn has joined #ocaml
c74d has joined #ocaml
milosn has quit [Read error: Connection reset by peer]
_andre has joined #ocaml
thomasga has quit [Quit: Leaving.]
ygrek has quit [Ping timeout: 256 seconds]
Hannibal_Smith has joined #ocaml
jonludlam has quit [Ping timeout: 264 seconds]
<RichN>
Does anyone have experience with LWT?
milosn has joined #ocaml
milosn has quit [Read error: Connection reset by peer]
<reynir>
A bit
octachron has joined #ocaml
osa1 has joined #ocaml
milosn_ has joined #ocaml
<RichN>
Given: Lwt.pick [recv s; timeout 2.0], if data arrives over the socket, the timeout thread is cancelled. If the timeout occurs, the recv is cancelled.
<RichN>
Now if I change it to: Lwt.pick [send s b >> recv s; timeout 2.0], I want the send/recv transaction to entirely complete or not. I guess 'send' is a bad example to use since you can't un-send if the timeout occur.
milosn_ has quit [Client Quit]
milosn__ has joined #ocaml
<RichN>
My question is, though, if I make a more complicated thread by composing simpler ones and then use it in a Lwt.pick list, what happens when a thread is partially complete when another fully terminates?
milosn__ is now known as milosn
<companion_cube>
I don't think you can do such transactions
<companion_cube>
even at the OS level, you might read/receive successfully, and then block on write/send
<companion_cube>
block for arbitrarily long that is
<ousado>
you can ensure at protocol level that a transaction terminates in a given time frame
<reynir>
ls
<reynir>
oops
<ousado>
if you don't receive the final ack within that period, whether stuff is in send/recv queues or not, it failed, as far as your application is concerned
<RichN>
I can agree with that.
<ousado>
of course the protocol has to have a notion of such a final acknowledgement
<RichN>
What about something like "recv s b >> xlat b >>= Lwt_mvar.put". I want to read a chunk of data, parse it into an internal type and write to an MVar.
<RichN>
The recv and the Lwt_mvar.put could block.
<RichN>
If I used Lwt.choose instead of Lwt.pick, could I re-apply the partially complete thread?
milosn has quit [Ping timeout: 256 seconds]
<ousado>
hm, what does "block" mean in this context? the menaing "blocking" in an async IO context is kind of occupied by "syscalls that don't return immediately"
<ousado>
*meaning
<ousado>
*meaning of, even
<RichN>
I guess the correct term is "sleep" until it can complete (either data is in the socket or the MVar is empty.)
<ousado>
OK, I'd call that waiting for notification
TheLemonMan has quit [Remote host closed the connection]
<RichN>
So in the example I gave about, there are two threads that may end up waiting for notification.
<RichN>
above*
nojb has joined #ocaml
<RichN>
Right now, I'm using Lwt.pick with a list of simple threads (not composition) and LWT works great. I was curious if some sort of composition was possible because, in some cases, it would clean up the code.
<ousado>
I have very little experience with Lwt, but I think you want join instead of choose if you care about all threads
<nojb>
RichN: you have to be careful - Lwt's cancellation semantics are not very clear
<nojb>
non-atomic threads may get cancelled midway
<nojb>
if you care about atomicity then you have to do it explicitly in your code
<RichN>
Ah, so maybe: Lwt.protect (recv >> xlat >>= Lwt_mvar.put) would be better? Would that have a chance of working? :)
<RichN>
(I'm abbreviating the recv call...)
<nojb>
That thread cannot be cancelled at all
Submarine has joined #ocaml
<RichN>
Rats. That's right; once it's waiting for recv, Lwt.pick has no hope of cancelling it.
<ousado>
"protected thread creates a new cancelable thread which behave as thread except that cancelling it does not cancel thread" - not very clear indeed
<RichN>
(Since it's "inside" the scope of Lwt.protect.)
<RichN>
The LWT documentation is rough in spots. I've contributed a few patches to make it clearer. :)
<nojb>
indeed
jonludlam has joined #ocaml
<RichN>
I don't have the expertise to document how Lwt.protect internals work.
<ousado>
I think protected just exists to be able to reuse code for cancelable threads for threads you don't want to be cancelled ever
<RichN>
I was hoping the implementation was correct, even if the docs were confusing.
<ousado>
although.. the type is the same?
<nojb>
cancellable threads should be used very carefully - their semantics are not clear - I would suggest only using them for atomic threads
<RichN>
I wonder if: (recv >> Lwt.protect (xlat >>= Lwt_mvar.put)) is the way to go.
<RichN>
The recv is cancellable. If it terminates, then the uncancellable part begins.
osa1 has quit [Ping timeout: 245 seconds]
<nojb>
if that 's what you want to do then there is a useful idiom to keep in mind Lwt.pick [ recv >>= fun () -> return `Ok | timeout >>= fun () -> return `Timeout ] >>= function `Ok -> xlat >>= Lwt_mvar.put | `Timeout -> ...
matason has quit []
<RichN>
Thanks. Maybe I'm trying to do too much in my pick list.
<RichN>
Thanks for the discussion and help! (Time to go to work.)
oscar_toro has quit [Ping timeout: 252 seconds]
jonludlam has quit [Ping timeout: 264 seconds]
matason has joined #ocaml
Hannibal_Smith has quit [Quit: Leaving]
thomasga has joined #ocaml
jonludlam has joined #ocaml
<companion_cube>
nojb: do you think it would be better to use continuations, in this particular style?
ollehar has quit [Remote host closed the connection]
ollehar has joined #ocaml
freling has quit [Quit: Leaving.]
<kmicinski>
I'm trying to use sexplib with syntax extensions and ocamlbuild
<kmicinski>
whenever I add a syntax(ocamlp4o) to my _tags I get
<kmicinski>
ocamlfind: Using -syntax, but no package is selected specifying a preprocessor as required for -syntax
<kmicinski>
I'm also using package(sexplib), but am I missing something here?
<bernardofpc>
+1 for updating opam with opam, (old wish from like 2 weeks ago...)
<smondet>
kmicinski: I think you need an argument to `-syntax`, like `-syntax camlp4o`
swgillespie has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<kmicinski>
Hmm.... so I'm trying this via ocamlbuild, but it generates the command ocamlfind ocamldep -syntax camlp4o -package sexplib -package ppx_deriving -modules interpreter.ml > interpreter.ml.depends
<kmicinski>
So I'm not sure what's happening, when I run that command manually I get an error, and yet there's clearly an argument to -syntax on the command line.
freling has joined #ocaml
<kmicinski>
Even stranger, it works fine from within Merlin.
<struk|work>
kmicinski: why are you adding camp4o w/o a camlp4 syntax extension?
<struk|work>
kmicinski: maybe you mean to add "sexplib.syntax" as a package?
<kmicinski>
When I only use sexplib.syntax I get the complier complaining that I have a syntax error
<struk|work>
kmicinski: are you using the sexplib extensions?
<kmicinski>
I am intending to, yes, and yet my question is: which flags do I need to add to my ocamlbuild "_tags" file to use the syntax extension.
<kmicinski>
e.g., I use `with sexp`
<struk|work>
well for starters, there's a chance it won't compile at all if you mix "with sexp" and "@@deriving foo" in the same module
<kmicinski>
struk|work: it looks almost right, but it's pretty bitrotted, e.g., I'm not able to resolve `ocamlfind_query`
<kmicinski>
I got to the poitn where I needed to include `Ocamlbuild_pack`
Hannibal_Smith has quit [Quit: Leaving]
djellemah_ has quit [Ping timeout: 265 seconds]
<kmicinski>
Duh, ignore my last comment, I'm just not getting `run_and_open` to typecheck.
<kmicinski>
alright, thanks for the pointer struk|work, with some tweaking I got it work, modulo some errors that are being generated by the syntax extension..
divyanshu has joined #ocaml
divyanshu has quit [Read error: Connection reset by peer]
<struk|work>
cool good luck
<struk|work>
I avoid campl4 extensions like the plague these days
divyanshu has joined #ocaml
divyanshu has quit [Read error: Connection reset by peer]
slash^ has quit [Read error: Connection reset by peer]
<ilia>
hello
MrScout has quit [Ping timeout: 245 seconds]
<ilia>
I have a very beginner question
Nijikokun has quit [Ping timeout: 245 seconds]
<ilia>
I am trying to declare a type
<ilia>
<ilia>
type point =
<ilia>
{ id : int;
<ilia>
x : int;
<ilia>
y : int;
<ilia>
z : int;
<ilia>
pref : <type definition goes here>;
<ilia>
cos_phi : float;
<ilia>
cos_theta : float;
<ilia>
mutable eff_modulo : float;
<ilia>
};;
<ilia>
<ilia>
pref is a pythonic dictionary int to int.
<ilia>
<ilia>
how to implement it?
<zozozo>
ilia: you can use a Mpa or a Hashtbl
<zozozo>
*Map
<ilia>
I was thinking about Map
<ilia>
Thanks
ontologiae_ has joined #ocaml
<ilia>
I tried this --> type dict = A of (int,int) Map.Poly.t with compare,sexp;;
<ilia>
and put 'dict' as a type for pref. It did not work
ontologiae has quit [Ping timeout: 250 seconds]
matason has joined #ocaml
<zozozo>
well, you have to make your module before you can use it
ollehar has quit [Remote host closed the connection]
<zozozo>
the Map module has a fonctor, which takes an implementation of a type with a compare function and return the correponsindg Map module
<zozozo>
so, to have a map from ints, you have to do something like :
kakadu_ has joined #ocaml
<zozozo>
module M = Map.Make(struct type t = int let compare = compare end)
<zozozo>
and then a map from int to int is represented by the type : int M.t
<ilia>
let me try
dav has quit [Ping timeout: 264 seconds]
Algebr has joined #ocaml
<zozozo>
ah, you seem to use Core, right ?
dav has joined #ocaml
<ilia>
yes, I do open Core.Std
<zozozo>
well then I suppose it'a a bit different
justgage has joined #ocaml
<ilia>
it works!!
<justgage>
Hey Ocamlers, I was wondering if there's any good library for date manipulation that you can recomend. I tried "calendar" and it didn't compile when I tried to install it via opam (I am a noob so I could have done it wrong)
<n3ss3s>
Hey. I have a format string, which works with Printf functions in utop, but when I try to it I get an error, both string and error are at http://pastebin.com/hTWrfXTH
ollehar has quit [Remote host closed the connection]
<struk|work>
n3ss3s: I can't see pastebin at work, but you have to pass a string literal to the formatter. most common issue. Eg. Printf.printf "" is good, but let f = "" in Printf.printf f is not
<n3ss3s>
I have defined the string as a format type
<n3ss3s>
let test_base: ('a, 'b, 'c) format =
<n3ss3s>
and it works fine in utop, but not when compiling
ollehar has joined #ocaml
<n3ss3s>
I have other format strings which work fine when compiling aswell, so I suspect there is something extremely annoying about this particular string I'm working with lol
freling has quit [Quit: Leaving.]
<apache2>
12
<struk|work>
n3ss3s: can you post to gists instead so I can see it? curious
<Drup>
Algebr: I would rather use Pprintast, if I were you
<Drup>
in compiler-libs
<Drup>
the result is not always the prettiest, but it works reasonably, almost.
<nojb>
that's what ppx_tools/rewriter uses
<Algebr>
Is there any simple example out there of what I'm trying to do?
<Drup>
Algebr: not that I know of, but it's really simple
<Drup>
just build something of type Parsetree.structure using usual builders (ppx_tools, Ast.helper, etc)
<Drup>
and call Pprintast.structure on it
<Denommus>
the error I'm getting is "Error: This expression has type (UL.t * string) React.event but an expression was expected of type (UL.t * string) React.event The type constructor UL.t would escape its scope"
<Denommus>
<Drup>
If you don't know about formatter, you can create a formatter from an out_channel with Format.formatter_of_out_channel
<Drup>
the other solution being, as nojb suggested, to write a regular ppx and then use rewriter when you want the ocaml file.
<Algebr>
Thank you, will try this out
Pepe_ has joined #ocaml
Pepe_ has quit [Client Quit]
<Drup>
Denommus: just pull the functor application out of the "let () ="
<Drup>
or, alternatively, pull the type t out of the functor, since it's independent of the argument
<Denommus>
Drup: I fixed it by specifying lifecycle type signature as let lifecycle: (t * Entity.t) event -> unit event = ...
Pepe_ has joined #ocaml
<Denommus>
Drup: ok, putting the type out of the functor also works