<ocaml190>
What is the idiomatic OCaml for outer and inner loops ?
<ocaml190>
I tend to write imperative code. Want functional.
<jbrown>
fold/map/iter?
<jbrown>
it depends what you're looping over, and why
<ocaml190>
I do something in the inner loop. Just over two ints m and n.
Algebr`` has joined #ocaml
<ocaml190>
Let's say I am doing this.
<ocaml190>
let x = x + 5 in let y = y + 5 in let width = 10 in let height = 10 in let update_rect = Gdk.Rectangle.create ~x ~y ~width ~height in area#misc#draw (Some update_rect)
<jbrown>
seems like quite an imperative thing, you might as well just use for loops
<jbrown>
I mean, you could write two nested recursive functions, or create lists of integers and iterate over them, but it wouldn't be better IMO
Algebr`` has quit [Ping timeout: 255 seconds]
<ocaml190>
[ zip (repeat i) [0..n-1] | i <- [0..m-1] ] in Haskell. Can't do it in OCaml ?
<jbrown>
there aren't comprehensions quite like that, no
<flux>
eons ago there was a campl4 syntax extension for that
<flux>
ocaml190, you can get a bit smaller by using let width, height = 10, 10 in ..
<flux>
and you shouldn't guard all match clauses. the last when .. should preferably become (* when m >= 5 *), ie. a comment
<twold>
is this just mapping over a range of x, y pairs? if so, you can simply nest List.map
<flux>
and perhaps the whole loop could be replaced with some nice range iteration from ie. Containers, Batteries or Core
<twold>
but I'd also like to know what would an idiomatic Ocaml look like
<flux>
personally I would just use for :-)
<flux>
and even when using loops like that, I would put the exit condition in the beginning of the function
<flux>
and just use plain 'if'
<ocaml190>
What is this range iteration ?
<flux>
let flip f a b = f b a flip List.iter CCList.(0 --^ 5) (fun n -> .. ) - pretty terrible ;-)
<flux>
(actually flip is defined in containers' CCFun)
<flux>
becomes slightly better when replace (fun n -> ..) with @@ fun n -> ..
<flux>
but if you don't need to return values and are doing purely imperative work, I think for loop is just fine :)
FreeBirdLjj has quit [Remote host closed the connection]
govg has joined #ocaml
nomicflux has joined #ocaml
govg has quit [Ping timeout: 240 seconds]
two_wheels has joined #ocaml
Algebr`` has joined #ocaml
Algebr`` has quit [Ping timeout: 255 seconds]
handlex has joined #ocaml
dhil has joined #ocaml
alienbot has joined #ocaml
nomicflux has quit [Quit: nomicflux]
handlex has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<zozozo>
say you want some modules to be linked in a binary for their side-effect (even though there is no dependency on them), what would be the simplest solution ? Up until now, since the modules had an empty interface I juste included them in my main.ml, but I'm starting to add visible interfaces for them, and it kind of breaks everything
<zozozo>
unfortunately, 'module _ = A' does not seem to be supported
<companion_cube>
I'd add a function `run:unit->unit` to these modules, and call that
handlex has joined #ocaml
<companion_cube>
Foo.run(); Bar.run();
<companion_cube>
this makes it clear that they are there only for side effects
<companion_cube>
doing `module A = Foo` might be dangerous because of module aliases
ocaml190 has quit [Ping timeout: 260 seconds]
unbalanced has joined #ocaml
<zozozo>
good idea
yomimono has joined #ocaml
mengu_ has joined #ocaml
mengu has quit [Ping timeout: 240 seconds]
defgeneric has quit [Ping timeout: 240 seconds]
defgeneric has joined #ocaml
Algebr`` has joined #ocaml
Algebr`` has quit [Ping timeout: 255 seconds]
johnelse has quit [Quit: leaving]
johnelse has joined #ocaml
ryanartecona has joined #ocaml
frug72 has quit [Ping timeout: 255 seconds]
beaumonta has joined #ocaml
mengu_ has quit [Remote host closed the connection]
frug72 has joined #ocaml
infinity0 has quit [Ping timeout: 240 seconds]
infinity0 has joined #ocaml
infinity0 has joined #ocaml
mengu has joined #ocaml
infinity0 has quit [Remote host closed the connection]
abeaumont has quit [Ping timeout: 260 seconds]
infinity0 has joined #ocaml
infinity0 has quit [Remote host closed the connection]
infinity0 has joined #ocaml
infinity0 has quit [Remote host closed the connection]
infinity0 has joined #ocaml
infinity0 has quit [Remote host closed the connection]
infinity0 has joined #ocaml
infinity0 has quit [Remote host closed the connection]
infinity0 has joined #ocaml
infinity0 has quit [Remote host closed the connection]
th5 has joined #ocaml
handlex has quit [Quit: handlex]
moei has joined #ocaml
MercurialAlchemi has quit [Ping timeout: 252 seconds]
jave has quit [Ping timeout: 248 seconds]
jave has joined #ocaml
flx has joined #ocaml
john51 has quit [Write error: Broken pipe]
mcspud has quit [Excess Flood]
john51 has joined #ocaml
flux has quit [Write error: Broken pipe]
kakadu has quit [Write error: Broken pipe]
flx is now known as flux
groovy2shoes has quit [Excess Flood]
kakadu has joined #ocaml
groovy2shoes has joined #ocaml
orbitz_ has joined #ocaml
dlat_ has joined #ocaml
profan_ has joined #ocaml
ciniglio_ has joined #ocaml
dlat has quit [Write error: Broken pipe]
profan has quit [Write error: Broken pipe]
ciniglio has quit [Write error: Broken pipe]
orbitz has quit [Write error: Broken pipe]
j0sh_ has joined #ocaml
ohama has quit [Disconnected by services]
__y has joined #ocaml
haesbaert has quit [Write error: Broken pipe]
haesbaer1 has joined #ocaml
ohama has joined #ocaml
snhmib has quit [*.net *.split]
louisriesener has quit [*.net *.split]
average has quit [*.net *.split]
ktosiek[m] has quit [*.net *.split]
M-jimt has quit [*.net *.split]
obadz has quit [*.net *.split]
unbalancedparen has quit [*.net *.split]
_y has quit [*.net *.split]
vinoski has quit [*.net *.split]
dch has quit [*.net *.split]
voglerr has quit [*.net *.split]
bigs_ has quit [*.net *.split]
noplamodo has quit [*.net *.split]
pitastrudl has quit [*.net *.split]
pote_ has quit [*.net *.split]
vishesh has quit [*.net *.split]
lyxia has quit [*.net *.split]
emias has quit [*.net *.split]
jbrown has quit [*.net *.split]
danieli has quit [*.net *.split]
RomanZ5 has quit [*.net *.split]
maker has quit [*.net *.split]
msch has quit [*.net *.split]
j0sh has quit [*.net *.split]
asm89 has quit [*.net *.split]
stephe has quit [*.net *.split]
grandy has quit [*.net *.split]
Balod has quit [*.net *.split]
jpdeplaix has quit [*.net *.split]
lpaste has quit [*.net *.split]
Exagone313 has quit [*.net *.split]
evhan has quit [*.net *.split]
S11001001 has quit [*.net *.split]
adi_____ has quit [*.net *.split]
mehdib has quit [*.net *.split]
thizanne has quit [*.net *.split]
bitbckt has quit [*.net *.split]
jpdeplaix has joined #ocaml
lyxia has joined #ocaml
Balod has joined #ocaml
obadz has joined #ocaml
emias has joined #ocaml
evhan has joined #ocaml
maker has joined #ocaml
Exagone313 has joined #ocaml
louisriesener has joined #ocaml
ggherdov has quit [Ping timeout: 258 seconds]
pote_ has joined #ocaml
pitastrudl has joined #ocaml
lpaste has joined #ocaml
asm89 has joined #ocaml
unbalancedparen has joined #ocaml
Rome has joined #ocaml
ktosiek[m] has joined #ocaml
M-jimt has joined #ocaml
snhmib has joined #ocaml
jbrown has joined #ocaml
danieli has joined #ocaml
grandy has joined #ocaml
noplamodo has joined #ocaml
vishesh has joined #ocaml
mehdib has joined #ocaml
thizanne has joined #ocaml
bitbckt has joined #ocaml
vinoski has joined #ocaml
unbalancedparen has quit [Max SendQ exceeded]
danieli has quit [Max SendQ exceeded]
grandy has quit [Max SendQ exceeded]
danieli_ has joined #ocaml
alienbot has quit [Read error: Connection reset by peer]
unbalancedparen has joined #ocaml
mcspud has joined #ocaml
pierpa has joined #ocaml
average has joined #ocaml
voglerr has joined #ocaml
Balod is now known as balod
adi_____ has joined #ocaml
stephe has joined #ocaml
ggherdov has joined #ocaml
pierpa` has joined #ocaml
dch has joined #ocaml
pierpa` has quit [Remote host closed the connection]
S11001001 has joined #ocaml
pierpa has quit [Quit: ERC Version 5.3 (IRC client for Emacs)]
ggherdov has quit [Excess Flood]
pierpa has joined #ocaml
alienbot has joined #ocaml
bigs_ has joined #ocaml
msch has joined #ocaml
ggherdov has joined #ocaml
alienbot has quit [Remote host closed the connection]
al-damiri has joined #ocaml
grandy_ has joined #ocaml
orbifx-m has joined #ocaml
yomimono has quit [Ping timeout: 258 seconds]
yomimono has joined #ocaml
thomasga has joined #ocaml
thomasga has quit [Client Quit]
thomasga has joined #ocaml
jao has joined #ocaml
MercurialAlchemi has joined #ocaml
larhat has quit [Quit: Leaving.]
ryanartecona has quit [Quit: ryanartecona]
handlex has joined #ocaml
Flerex has joined #ocaml
<Flerex>
Does anyone know why am I getting this error when compiling?
<Flerex>
warning: ignoring file {file}, file was built for unsupported file format ( 0x28 0x2A 0x6C 0x65 0x74 0x20 0x72 0x65 0x63 0x20 0x72 0x6C 0x69 0x73 0x74 0x20 ) which is not the architecture being linked (x86_64)
<companion_cube>
seems like you have files built for another architecture
<companion_cube>
try `make clean` or something like that?
<Flerex>
Didn't do anything
<Flerex>
it's a very simple file I'm trying to compile with ocamlc
<companion_cube>
how do you compile? can you remove all *.cm{i,o} files?
<Flerex>
I type ocamlc {file}
<Flerex>
and that's it
thomasga has quit [Quit: Leaving.]
Algebr`` has joined #ocaml
<companion_cube>
try to remove file.cmi file.cmo
<Flerex>
Same :S
<companion_cube>
that's very weird
<companion_cube>
(what if you copy your file somewhere else and try again? I really suspect a stale build file)
Algebr`` has quit [Ping timeout: 255 seconds]
<Flerex>
If I copy it and paste it on the interactive compiler (ocaml) it works
slash^ has joined #ocaml
<companion_cube>
I meant copy the file in another directory
thomasga has joined #ocaml
<Flerex>
It works now
<Flerex>
Yeah
<Flerex>
Weird
<Flerex>
Thanks! :)
sz0 has joined #ocaml
copy` has joined #ocaml
antkong has joined #ocaml
Denommus has joined #ocaml
mfp has quit [Ping timeout: 255 seconds]
Denommus has quit [Client Quit]
Denommus has joined #ocaml
shinnya has joined #ocaml
vicfred has joined #ocaml
jnavila has quit [Quit: It was time]
orbifx-m has quit [Ping timeout: 252 seconds]
xorpse has quit [Ping timeout: 248 seconds]
mengu has quit [Remote host closed the connection]
mengu has joined #ocaml
tane has joined #ocaml
mfp has joined #ocaml
larhat has joined #ocaml
ryanartecona has joined #ocaml
shinnya has quit [Ping timeout: 276 seconds]
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
agarwal1975 has joined #ocaml
thomasga has quit [Quit: Leaving.]
zpe has quit [Ping timeout: 252 seconds]
balod has quit [Remote host closed the connection]
simon3 has joined #ocaml
balod has joined #ocaml
mengu has quit [Remote host closed the connection]
sepp2k has quit [Ping timeout: 255 seconds]
philtor has joined #ocaml
orbifx-m has joined #ocaml
antkong has quit [Quit: antkong]
handlex has quit [Quit: handlex]
Algebr`` has joined #ocaml
Algebr`` has quit [Ping timeout: 255 seconds]
handlex has joined #ocaml
Algebr``` has joined #ocaml
simon3 has quit [Remote host closed the connection]
wolfcore has quit [Ping timeout: 255 seconds]
smondet has joined #ocaml
isd has joined #ocaml
kakadu has quit [Quit: Konversation terminated!]
malc_ has joined #ocaml
wolfcore has joined #ocaml
simon3 has joined #ocaml
rgrinberg has joined #ocaml
Onemorenickname has joined #ocaml
<Onemorenickname>
Hello people
<Onemorenickname>
and i solved my problem
<Onemorenickname>
you are so good i don't even need to ask you any question
<companion_cube>
indeed
simon3 has quit [Remote host closed the connection]
emacs-fb has joined #ocaml
<companion_cube>
congratulations for solving your issue!
ygrek has joined #ocaml
ryanartecona has quit [Quit: ryanartecona]
<orbifx-m>
Flerex: did you use any prebuilt libraries?
wtetzner has joined #ocaml
<reynir>
:D
<orbifx-m>
oops, there is more log 😝
omar__ has joined #ocaml
Onemorenickname has quit [Read error: Connection reset by peer]
ryanartecona has joined #ocaml
Onemorenickname has joined #ocaml
Onemorenickname has quit [Read error: Connection reset by peer]
Onemorenickname has joined #ocaml
Onemorenickname has quit [Read error: Connection reset by peer]
malc_ has quit [Remote host closed the connection]
Onemorenickname has joined #ocaml
<emacs-fb>
So I'm having this rather strange issue that seems to center around using a Format.formatter to write to a file. I expect to be able to write the file and flush and then close the backing channel, but what I see instead is that the last line is dropped.
<emacs-fb>
But only when writing to a file -- not when writing to stdout (which can be toggled via command line)
<emacs-fb>
I don't know what question to ask, except "why?"
Anarchos has joined #ocaml
<companion_cube>
you need to flush the formatter as well
<companion_cube>
e.g. @. will flush
<companion_cube>
(use "@." rather than "\n" in Format)
<companion_cube>
ok, so: a big red flag for me is "set_formatter_out_channel"
<emacs-fb>
My apologies!
<emacs-fb>
Why is that a red flag?
<companion_cube>
it's modifying a global variables
<companion_cube>
and global variables are bad, m'kay? :D
<companion_cube>
use Format.fprintf whenever you have a formatter that is not {stdout,stderr}, as a good rule of thumb
<emacs-fb>
Good point.
<companion_cube>
and the pp_* combinators instead of the ones working on the std formatter
<companion_cube>
so `Format.fprintf my_formatter "@[%s@]@."` instead of redirecting to stdout and then using `Format.printf`
<emacs-fb>
The only problem is, the do_some_printing() is a large lib that (at first) picks either to write to output_chan or output_formatter based on a command line flag & some modes.
<emacs-fb>
I am not sure how it does its printing internally.
<companion_cube>
:s
<companion_cube>
is this a lib you don't have any control on?
<companion_cube>
(as a workaround if it's the case, try `pp_print_flush output_formatter ()`)
<emacs-fb>
Sort of. It is a lib that does AST printing but also it uses the default OCaml AST printer, so I have control over the part that does its own printing. For the most part.
<companion_cube>
well, good style (imho) would dictate that the printing is done on a `formatter` passed as argument
voglerr has quit [Quit: Connection closed for inactivity]
<companion_cube>
typically a printer for `foo` has type `Format.formatter -> foo -> unit`
<emacs-fb>
Er, does that return a function that I have to then call?
<emacs-fb>
(pp_print flush)
<companion_cube>
no, no
<companion_cube>
it's like `print_flush ()` but you pass a formatter: `pp_print_flush formatter ()`
wtetzner has quit [Remote host closed the connection]
<emacs-fb>
val pp_print_flush : formatter -> unit -> unit
<emacs-fb>
What is the second unit?
<reynir>
the return type
<companion_cube>
it takes unit and returns unit
<emacs-fb>
Rather, why does it take unit?
<companion_cube>
ah
<emacs-fb>
Consistency's sake for the other pp_*?
<companion_cube>
it's because the `Format.formatter -> 'a -> unit` is so pervasive
<companion_cube>
yeah
<emacs-fb>
Oh, okay
wtetzner has joined #ocaml
<companion_cube>
emacs-fb: it's so it works with %a
<emacs-fb>
Holy guacamole I think that pp_print_flush worked
<reynir>
\o/
<emacs-fb>
Do I need to have flush output_chan if I have pp_print_flush?
<emacs-fb>
companion_cube: This has been hours of grief. Thank you.