<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
<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
<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>
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]
<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