adrien changed the topic of #ocaml to: Discussions about the OCaml programming language | http://www.ocaml.org | OCaml 4.06.0 release notes: https://caml.inria.fr/pub/distrib/ocaml-4.06/notes/Changes | Try OCaml in your browser: http://try.ocamlpro.com | Public channel logs at http://irclog.whitequark.org/ocaml
<dmbaturin> GreyFaceNoSpace: One possible approach for a functional sieve is to store already found prime numbers in a list, and make the next_prime function try to divide the number by them all if it's greater than one.
<GreyFaceNoSpace> dmbaturin, can u give me tips on how to change my mindset regarding functional programming? i am struggling alot. is it meant to be that clunky? or is it just because i am inexperienced?
<dmbaturin> Some tasks just lend more to either imperative or functional approach. Sieve of Eratosphenes is definitely one of the former. Handling complex datastructures tends to be the other way around.
<dmbaturin> Yes, it takes experience to learn the new mindset.
<dh_work> programming is programming -- some languages make some things awkward but everything's fundamentally similar everywhere
<dh_work> however, this perspective is not usually accessible to beginners for some time :(
<GreyFaceNoSpace> sadly
<GreyFaceNoSpace> i think its really interesting
<GreyFaceNoSpace> but just needs a lot of time
sh0t has quit [Ping timeout: 240 seconds]
<GreyFaceNoSpace> which unfortunately i do not have
<dh_work> probably the best way to think about the problems you're probably having is: instead of thinking in terms of updating the existing things you have
<dh_work> think about making new things that are slightly different from the old things
<dh_work> e.g. if you have a list of widgets and you want their ID numbers, make a new list
<dh_work> or if you have a list of full names and you want a list of last names, make a new list of the new strings
<dh_work> that kind of thing
<dh_work> let the compiler worry about the inefficiency
<GreyFaceNoSpace> yes i understand that
<dh_work> (it mostly won't help that much, but if you're using a functional language, one of the premises is that maximum efficiency is a secondary consideration)
<dh_work> (now I'm going to get a lot of heat from the jane streeters)
<GreyFaceNoSpace> my problem however is with program flow if it makes any sense. sometimes im just stuck there not knowing what to write. like normaly with imperative programming u think in steps: do this then do this ... here its really awkward.
<dh_work> also, don't let the functional doctrine enforcers stop you from using refs where it makes sense to
<dh_work> (except where you have to because someone's grading it with those notions in mind)
sh0t has joined #ocaml
<dh_work> oh
<GreyFaceNoSpace> yea i am not allowed to use refs/arrays/or loops of course
<dh_work> it's not different actually
<dh_work> do x then do y is: let foo = x in let bar = y in x + y (or osmething like that)
<dmbaturin> x |> foo |> bar
<dh_work> if you aren't allowed refs, everything you update has to appear as a return value, so you'll always have some value to let-bind in the sequence
<dmbaturin> http://baturin.org/code/files/unparsing.ml This is a spectacular example of the power of composition and continuation passing.
<thizanne> GreyFaceNoSpace: a vision of functional programming that I like it that, rather than focusing on steps to solve a problem, it focuses on transformation of values
<thizanne> so rather than thinking "I should do this, then that", you think "first I should construct this value from the input, then this one from the previous one"
<dh_work> and loops convert directly to recursive functions
<dh_work> loops that update state are recursive functions that pass the state explicitly to/from the recursive calls
<dh_work> most routine loops are ugly as recursive functions; but most routine loops can be written with map or fold
<GreyFaceNoSpace> dh_work, yea i usually translate my loops in to endrecursive functions but my god does it look ugly.
<thizanne> for recursive functions, the question to ask is "I must get the right result for this complex value. If I can somehow get the right result from its (simpler) component, how can I build the final result ?"
<dh_work> one of my recommendations is: make friends with fold
<dh_work> this came naturally for me because years ago when I first had to take up haskell I'd already had lots of experience with unix shell scripts and pipelines, which are pretty much folds over lists of lines of text
<dh_work> that was a long time ago now though :-)
<GreyFaceNoSpace> thanks for the help guys. I really appreciate it :D
<GreyFaceNoSpace> i'll keep working on it
<GreyFaceNoSpace> and see where it goes
<dh_work> and basically everything you'd write as a halfway-sane loop in e.g. java can be a fold in haskell or ocaml
<dmbaturin> https://my.mixtape.moe/xktxra.pdf This is the thing I never can find time to finish, lol.
<GreyFaceNoSpace> i'll try to implement belman-ford as practice tomorrow
<dh_work> (insane loops are best avoided, obviously; the only real exception I can think of is a workqueue, where the loop is over a non-constant list in a structured way, but not a structured way that can be made a fold nicely)
<GreyFaceNoSpace> dh_work, what about nested loops. i have trouble implementing those functionally
<GreyFaceNoSpace> i always get lost
<dh_work> write the loop form first, refactor the inner loop into a different procedure first, then translate that
<GreyFaceNoSpace> and start getting wrong types since i can't follow anymore
<dh_work> after you do a few you won't need to do it in longhand any more
<GreyFaceNoSpace> ok will do that
<dmbaturin> Note that you can have mutually recursive functions.
<dh_work> sometimes you'll actually want to refactor it into one big loop
<GreyFaceNoSpace> dmbaturin, yea...i almost forgot about that
<dh_work> sometimes the best thing to do is to manufacture a list of the cases first, and then do a map over that
<GreyFaceNoSpace> dmbaturin, never got to use it. just saw it in calss once
<dh_work> also, write down the types explicitly
<dmbaturin> Generally, typed functional programming is largely proof by case analysis.
<dh_work> type inference is not always your friend, especially as a beginner.
<GreyFaceNoSpace> dh_work, this!!!!!!!!!!
<GreyFaceNoSpace> i hate it...
<Drup> you will learn to like it
<dh_work> I wouldn't say that
<Drup> You *need* merlin though
<dh_work> you will learn to tolerate it, you might learn to like it
<GreyFaceNoSpace> quick question regarding writing types.
<Drup> dh_work: you haven't learned it yet :D
<Drup> it will come :]
<GreyFaceNoSpace> lets say i have a function : let f a b = a * b
<dh_work> you underestimate my age and level of crankiness :-)
<GreyFaceNoSpace> if i write : let f a:int b:int = a * b
<GreyFaceNoSpace> i get errors
<Drup> GreyFaceNoSpace: parens!
<dh_work> let f (a: int) (b: int) : int = a * b
<GreyFaceNoSpace> oh
<GreyFaceNoSpace> thanks!
<GreyFaceNoSpace> am i forcing my types now? or is it just for clarity?
<dh_work> some of both
<Drup> alternatively, if you are a repressed Haskellist:
<Drup> let f : int -> int -> int
<Drup> = fun a b -> a * b
<dh_work> if you write that, and then accidentally call it as f "xyz"
<dh_work> the error will make more sense to you
chat_ has quit [Ping timeout: 255 seconds]
<dh_work> plus it helps you think about what the types are that you're intending to use
<GreyFaceNoSpace> thank you very much everyone
<GreyFaceNoSpace> really appreciate the help
* dh_work bows
<GreyFaceNoSpace> i'll be back tomorrow
<GreyFaceNoSpace> gotta sleep now
<dmbaturin> GreyFaceNoSpace: ...i.e. you identify the cases, define the solution for the trivial case, then see what you need to do for non-trivial ones by reducing them to trivial. For example, you want to see if a list is sorted. The trivial case is the empty list, it's already sorted by definition. The next case is a list of a single element, which is also sorted by definition. Next we have a list of two elements, which is sorted iff cmp(first, second) = ...
<dmbaturin> ... true. Then for arbitrary list, we can say that [first, second] is sorted and [second, rest] is sorted.
<dmbaturin> * is sorted when
GreyFaceNoSpace has quit [Quit: Ex-Chat]
Pierpa has joined #ocaml
sh0t has quit [Ping timeout: 265 seconds]
Pierpa has quit [Quit: Page closed]
onanyme has joined #ocaml
<onanyme> greetings
<onanyme> I'm having difficulties to build my ocaml project this morning after upgrading my ubuntu 16.04 build env both on travis CI, ubuntu for windows
<onanyme> tried to reproduce on a base ubuntu 16.04 server this morning, base opam install with core
infinity0_ has joined #ocaml
infinity0 has quit [Killed (orwell.freenode.net (Nickname regained by services))]
infinity0 has joined #ocaml
infinity0_ is now known as infinity0
VermillionAzure has joined #ocaml
<onanyme> trying to build a simple test.ml
<onanyme> open Core;;
<onanyme> Out_channel.print_endline "Test";;
zlsyx has quit [Remote host closed the connection]
<onanyme> ubuntu@ip-172-30-0-161:~/test$ corebuild test.native
<onanyme> + ocamlfind ocamlopt -linkpkg -g -thread -package core,core_kernel,base -package core test.cmx -o test.native
<onanyme> Stdio__ referenced from test.cmx
<onanyme> Error: No implementations provided for the following modules:
<onanyme> File "_none_", line 1:
<onanyme> Core_kernel__ referenced from test.cmx
zlsyx has joined #ocaml
<onanyme> ocaml 4.05 / core 0.10
<onanyme> ~/test$ which ocamlfind
<onanyme> /home/ubuntu/.opam/4.05.0/bin/ocamlfind
<dh_work> something about the installation is borked; my first guess would be inconsistent or wrong opam manipulations
<dh_work> e.g. some things are installed for different ocaml versions, maybe
<onanyme> once my EC2 instance is up, I simply do
<onanyme> sudo apt-get install make m4 gcc unzipwget https://raw.github.com/ocaml/opam/master/shell/opam_installer.sh -O - | sh -s /usr/local/bin
<Enjolras> onanyme: what's your jbuilder version ?
<onanyme> opam list says jbuilder 1.0+beta18
<Enjolras> seen a similar error with jbuilder beta18
<Enjolras> downagraded to beta17, rebuilt core_kernel
<onanyme> will try that
<onanyme> thks man
<dh_work> bah, silly me not first assuming upstream is broken ;-)
<Enjolras> jbuilder is still called "beta" for a reason :)
<onanyme> slightly better after the downgrade, only complains about Stdio__ now
<onanyme> nice, it works
<onanyme> that was it
am55 has joined #ocaml
<onanyme> saved my day @Enjolras
am55 has quit [Quit: am55]
onanyme has quit [Quit: Leaving]
letoh has joined #ocaml
am55 has joined #ocaml
sh0t has joined #ocaml
silver has quit [Read error: Connection reset by peer]
am55 has quit [Quit: am55]
Vermie has joined #ocaml
Vermie has quit [Read error: Connection reset by peer]
VermillionAzure has quit [Ping timeout: 240 seconds]
isd has joined #ocaml
sh0t has quit [Remote host closed the connection]
jonh has joined #ocaml
jao has joined #ocaml
dviper has quit [Quit: Leaving]
mfp has quit [Ping timeout: 260 seconds]
isd has quit [Quit: Leaving.]
al-damiri has quit [Quit: Connection closed for inactivity]
jimmyrcom has joined #ocaml
govg has quit [Ping timeout: 260 seconds]
Pierpa has joined #ocaml
govg has joined #ocaml
theblatte has quit [Ping timeout: 248 seconds]
theblatte has joined #ocaml
zlsyx has quit [Remote host closed the connection]
zlsyx has joined #ocaml
nobleach has joined #ocaml
nobleach has quit [Quit: leaving]
zlsyx has quit [Remote host closed the connection]
zlsyx has joined #ocaml
zlsyx has quit [Remote host closed the connection]
zlsyx has joined #ocaml
zlsyx has quit [Remote host closed the connection]
pyx has joined #ocaml
pyx has quit [Client Quit]
<_xvilka_> Hi!
<_xvilka_> How to create pointer to a pointer using Ctypes?
<_xvilka_> e.g. I have type "mystruct" and have to define a function "int myfunc(struct mystruct **context)"
<_xvilka_> "addr (addr context)" obviously wont work
sz0 has joined #ocaml
jao has quit [Ping timeout: 260 seconds]
gtrak has quit [Ping timeout: 240 seconds]
gtrak has joined #ocaml
Pierpa has quit [Quit: Page closed]
<_xvilka_> wonder why such a basic feature is not documented anywhere, sigh
spew has joined #ocaml
spew has quit [Ping timeout: 240 seconds]
<dh_work> double-pointers confuse non-C programmers :-)
butterthebuddha has quit [Max SendQ exceeded]
MercurialAlchemi has joined #ocaml
butterthebuddha has joined #ocaml
Haudegen has joined #ocaml
jimmyrcom has quit [Ping timeout: 240 seconds]
cbot has quit [Quit: Leaving]
MercurialAlchemi has quit [Ping timeout: 240 seconds]
govg has quit [Ping timeout: 248 seconds]
govg has joined #ocaml
MercurialAlchemi has joined #ocaml
hannes` has joined #ocaml
hannes has quit [Read error: Connection reset by peer]
_whitelogger has joined #ocaml
_whitelogger_ has quit [Remote host closed the connection]
tarptaeya has joined #ocaml
jimt has quit [Quit: leaving]
dhil has joined #ocaml
jimt has joined #ocaml
Haudegen has quit [Read error: Connection reset by peer]
jimt has quit [Quit: WeeChat 1.4]
jimt has joined #ocaml
jimt has quit [Client Quit]
nahra has quit [Remote host closed the connection]
dhil has quit [Ping timeout: 276 seconds]
madroach has quit [Quit: leaving]
mk9 has quit [Quit: mk9]
jimt has joined #ocaml
argent_smith has joined #ocaml
sz0 has quit [Quit: Connection closed for inactivity]
kakadu has joined #ocaml
zpe has joined #ocaml
jimt has quit [Quit: WeeChat 1.4]
jimt has joined #ocaml
ygrek has joined #ocaml
bartholin has quit [Ping timeout: 276 seconds]
kark has quit [Ping timeout: 252 seconds]
jimmyrcom has joined #ocaml
<_xvilka_> asked the same question in GitHub and StackOverflow
<_xvilka_> so far no answers
jbrown has quit [Remote host closed the connection]
<Armael> _xvilka_: use Ctypes.allocate
<Armael> (I think?)
<Armael> mmh maybe not
<Armael> allocate (ptr int) (coerce (ptr void) (ptr int) null)
<Armael> this gives you a int ptr ptr
<Armael> so yea
bartholin has joined #ocaml
<Armael> "allocate (ptr int) (from_voidp int null)" a bit shorter
<_xvilka_> can I do the same with structure?
<_xvilka_> "allocate (ptr mytype) (from_voidp int null)"?
<Armael> yes (you also need to replace the second occurence of "int" by "mytype")
<_xvilka_> cool
<Armael> what it means is that you allocate a memory cell for a pointer (hence you get a pointer to pointer)
<Armael> this memory cell is initialized with NULL; you pass (a pointer to) it to the function, which will probably modify it to contain an pointer to an actual structure
<_xvilka_> yeah, I got what it means
<_xvilka_> thank you
jimmyrcom has quit [Ping timeout: 260 seconds]
neubyi has quit [Quit: .]
gtrak has quit [Ping timeout: 252 seconds]
gtrak has joined #ocaml
maattdd_ has joined #ocaml
mfp has joined #ocaml
zlsyx has joined #ocaml
dhil has joined #ocaml
zlsyx has quit [Ping timeout: 240 seconds]
p_d has joined #ocaml
butterthebuddha has quit [Max SendQ exceeded]
butterthebuddha has joined #ocaml
demonimin_ has joined #ocaml
ziyourenxiang has joined #ocaml
demonimin has quit [Ping timeout: 265 seconds]
TarVanimelde has joined #ocaml
TarVanimelde has quit [Client Quit]
johnelse is now known as johnel_away
johnel_away is now known as johnelse
neubyi has joined #ocaml
<infinity0> Enjolras: ah ok thanks, looking forward to it :)
jimmyrcom has joined #ocaml
shinnya has joined #ocaml
<infinity0> although, i imagined that rust could just ignore the ocaml runtime, and rather ocaml code could just call into rust code like normal C code, using "pub extern "C" fn"
<infinity0> and using Ctypes or something
am55 has joined #ocaml
zolk3ri has joined #ocaml
<Enjolras> infinity0: using ctypes yes you can. But it's actually 1) slow for structs 2) not helpful, because Ctypes is for C
<Enjolras> and if you want to pass say an enum and get a rust enum
<Enjolras> you need to do it manually anyway
<Enjolras> even like options
<Enjolras> so ctypes does not bring much benefits it's almost like writing stubs by hand now that there is the ocaml crate
<Enjolras> would be nice to write rusttypes but that scares me, so i went middle ground with ocaml-derive
sh0t has joined #ocaml
jimt has quit [Quit: jimt]
p_d has quit [Ping timeout: 240 seconds]
jimt has joined #ocaml
am55 has quit [Quit: am55]
dhil has quit [Ping timeout: 240 seconds]
spew has joined #ocaml
sh0t has quit [Ping timeout: 245 seconds]
spew has quit [Ping timeout: 240 seconds]
xutux has joined #ocaml
shinnya has quit [Ping timeout: 256 seconds]
xutux has quit [Ping timeout: 248 seconds]
jimmyrcom has quit [Ping timeout: 256 seconds]
jao has joined #ocaml
am55 has joined #ocaml
am55 has quit [Quit: am55]
dhil has joined #ocaml
am55 has joined #ocaml
spew has joined #ocaml
<infinity0> Enjolras: ah ok that makes sense
zlsyx has joined #ocaml
jao has quit [Ping timeout: 252 seconds]
xutux has joined #ocaml
xutux_ has joined #ocaml
xutux has quit [Ping timeout: 265 seconds]
govg has quit [Ping timeout: 240 seconds]
xutux__ has joined #ocaml
govg has joined #ocaml
xutux_ has quit [Ping timeout: 260 seconds]
xutux__ has quit [Ping timeout: 260 seconds]
sh0t has joined #ocaml
gtrak has quit [Ping timeout: 255 seconds]
maattdd_ has quit [Ping timeout: 240 seconds]
maattdd_ has joined #ocaml
gtrak has joined #ocaml
rwmjones has quit [Ping timeout: 240 seconds]
rwmjones has joined #ocaml
FreeBirdLjj has joined #ocaml
gtrak has quit [Ping timeout: 260 seconds]
gtrak has joined #ocaml
Geekingfrog has quit [Ping timeout: 256 seconds]
MercurialAlchemi has quit [Ping timeout: 252 seconds]
Geekingfrog has joined #ocaml
am55 has quit [Quit: am55]
zlsyx has quit [Remote host closed the connection]
mfp has quit [Ping timeout: 256 seconds]
<companion_cube> it seems linenoise is dead :/
mbuf has joined #ocaml
<leah2> there is a linenoise-ng
<leah2> uses c++ tho
<companion_cube> any opinion on libedit?
<companion_cube> erg
<companion_cube> oh well, I guess linenoise will be enough for now…
zlsyx has joined #ocaml
al-damiri has joined #ocaml
zlsyx has quit [Remote host closed the connection]
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
zlsyx has joined #ocaml
zpe has quit [Ping timeout: 248 seconds]
argent_smith has quit [Ping timeout: 260 seconds]
zlsyx has quit [Quit: Leaving...]
ygrek has quit [Ping timeout: 240 seconds]
xutux has joined #ocaml
xutux_ has joined #ocaml
xutux has quit [Ping timeout: 252 seconds]
xutux__ has joined #ocaml
xutux_ has quit [Ping timeout: 252 seconds]
zlsyx has joined #ocaml
mfp has joined #ocaml
xutux__ has quit [Ping timeout: 240 seconds]
xutux has joined #ocaml
argent_smith has joined #ocaml
mbuf has quit [Quit: Leaving]
zlsyx has quit [Quit: Leaving...]
dhil has quit [Ping timeout: 260 seconds]
FreeBirdLjj has quit [Remote host closed the connection]
zlsyx has joined #ocaml
xutux_ has joined #ocaml
sh0t has quit [Remote host closed the connection]
sh0t has joined #ocaml
xutux has quit [Ping timeout: 276 seconds]
jnavila has joined #ocaml
jnavila has quit [Client Quit]
jnavila has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
zpe has joined #ocaml
maattdd_ has quit [Ping timeout: 256 seconds]
maattdd_ has joined #ocaml
tane has joined #ocaml
xutux_ has quit [Ping timeout: 256 seconds]
xutux has joined #ocaml
maattdd_ has quit [Ping timeout: 256 seconds]
Algebr has joined #ocaml
xutux has quit [Ping timeout: 265 seconds]
xutux has joined #ocaml
jnavila has joined #ocaml
Algebr has quit [Remote host closed the connection]
maattdd_ has joined #ocaml
xutux_ has joined #ocaml
SiGe has joined #ocaml
xutux has quit [Ping timeout: 240 seconds]
jnavila has quit [Ping timeout: 240 seconds]
xutux_ has quit [Ping timeout: 240 seconds]
maattdd_ has quit [Ping timeout: 276 seconds]
jnavila has joined #ocaml
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 256 seconds]
iitalics has joined #ocaml
sh0t has quit [Ping timeout: 255 seconds]
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 252 seconds]
iitalics has quit [Quit: WeeChat 2.0.1]
<Leonidas> Enjolras: can you even write rusttypes? Does Rust have an ABI?
<companion_cube> rust can use the C ABI when needed
<companion_cube> that's all I know
<Leonidas> yes, but that's just as bad as C++
tarptaeya has quit [Quit: Leaving]
<companion_cube> ok, so:
<companion_cube> #use "";;
<companion_cube> reads from stdin oO
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 240 seconds]
tarptaeya has joined #ocaml
SiGe has quit [Remote host closed the connection]
nullifidian has quit [Remote host closed the connection]
AltGr has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
AltGr has left #ocaml [#ocaml]
maattdd_ has joined #ocaml
xutux has joined #ocaml
maattdd_ has quit [Ping timeout: 240 seconds]
isd has joined #ocaml
jnavila has joined #ocaml
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 260 seconds]
tarptaeya has quit [Quit: Leaving]
argent_smith has quit [Quit: Leaving.]
tane has quit [Quit: Leaving]
jnavila has joined #ocaml
jnavila has quit [Ping timeout: 240 seconds]
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 240 seconds]
spew has quit []
gtrak has quit [Ping timeout: 260 seconds]
jao has joined #ocaml
kakadu has quit [Remote host closed the connection]
jnavila has joined #ocaml
maattdd_ has joined #ocaml
sh0t has joined #ocaml
maattdd_ has quit [Ping timeout: 240 seconds]
jnavila has quit [Remote host closed the connection]
sh0t has quit [Remote host closed the connection]
sh0t has joined #ocaml
xutux has quit [Ping timeout: 248 seconds]
xutux has joined #ocaml
xutux has quit [Ping timeout: 260 seconds]
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 240 seconds]
maattdd_ has joined #ocaml
<Enjolras> Leonidas: you can codegen
<Enjolras> it would not be totally rusttypes but you can generate rust code from ocaml to map back from c abi to rust
maattdd_ has quit [Ping timeout: 265 seconds]
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 240 seconds]
spew has joined #ocaml
maattdd_ has joined #ocaml
maattdd_ has quit [Ping timeout: 256 seconds]
spew has quit [Remote host closed the connection]
spew has joined #ocaml
isd has quit [Ping timeout: 245 seconds]
spew has quit [Ping timeout: 240 seconds]
maattdd_ has joined #ocaml
isd has joined #ocaml