<Moataz-E>
I am trying to solve the first Euler problem in ocaml
<Moataz-E>
just decided to learn the language today
<Moataz-E>
Sadly, i am facing a problem as the program is giving unexpected results. I wrote a quick python script that does the exact same thing but gives the correct solution
Eyyub has joined #ocaml
<Moataz-E>
can anybody help me spot the error? Also, if possible, any ocaml tips regarding better ways to code something are highly appreciated
<Kakadu>
Can you paste link to original problem text?
<pminten>
Moataz-E: are you mainly trying to learn solving the Euler problems or to learn OCaml?
<Moataz-E>
OCaml
<pminten>
if it's about learning OCaml and getting feedback on your code exercism.io might be worth looking at as it's more focussed on feedback
<pminten>
(truth be told there aren't many experienced OCamlers doing the nitpicking there, there's currently just two people new to the language as well)
<Moataz-E>
pminten: I see, I've heard of that website but never tried. I would love to use it as practise but i also like to test new languages on euler's problems as they get quite challenging later on.
<pminten>
yeah, exercism doesn't really have very challenging exercises, though there is at least one in the OCaml track that's semi-challenging if you haven't used zippers before
<pminten>
as for your code I'd probably write the arg parsing like this: `[| multiple1; multiple2; limit |] = Array.map int_of_string Sys.argv`
<Moataz-E>
pminten: zippers as in the zip function? I know it from Haskell
<pminten>
Moataz-E: not quite, zippers as in tree zippers
<oriba>
Why is cmd_args a "doc_t aggregation_t list" and not a "operation_t * doc_t aggregation_t list" ??
<oriba>
And why does it accept two different kind of types in the list?
<dsheets>
oriba, ; is end statement
<dsheets>
oriba, , is tuple product
<dsheets>
line 45 has a value, Get, that constitutes a statement (you got a warning about it probably should be unit)
<dsheets>
make it a comma
<dsheets>
then you will get a type error on the next line
<oriba>
dsheets, OMG.... thats so stupid.... oh oh too much beer yesterday ;-)
<oriba>
dsheets, thanks!
<dsheets>
oriba, -w @F@S
<oriba>
?
<dsheets>
ocamlc -i -w @f@s evalreihenfolge.ml
<dsheets>
should now shoot you in the face
mcclurmc has quit [Remote host closed the connection]
<oriba>
messages do not look much different
<dsheets>
oriba, man ocamlc shows all the warnings
<dsheets>
it does not say that there was a fatal error due to warnings?
<dsheets>
i also like p, u, and 40
introom5 has joined #ocaml
<oriba>
I used the old 3.11.2 compiler. With 4.00.1 it does shout louder ;-)
mcclurmc has joined #ocaml
<oriba>
dsheets, I used the old 3.11.2 compiler. With 4.00.1 it does shout louder ;-)
<dsheets>
oh hm odd, i thought those were stable
<dsheets>
i only use 4.x
introom4 has quit [Ping timeout: 264 seconds]
ulfdoz has quit [Ping timeout: 246 seconds]
<oriba>
I have the old 3.11.2 on my system, and the new 4.x via opam
<oriba>
I'm exploring some features and want to see which compiler accepzts what. So thats why I sometimes use boith compilers
<dsheets>
afaik most users have moved to 4.00.1+ except maybe some banks
<oriba>
banks?
<ggole>
There are probably quite a few users who install whatever is provided by their package manager
<oriba>
BTW: the code I pasted... I want to explore how this can be made this way with the normal sum datatypes, and how I can make it easier with GADT then
introom5 has quit [Ping timeout: 240 seconds]
introom5 has joined #ocaml
<oriba>
A direct comparison of "how to od it with Sum types vs. how to do it with GADT" is, what I want to see.
mcclurmc has quit [Remote host closed the connection]
<oriba>
A direct comparison of "how to do it with Sum types vs. how to do it with GADT" is, what I want to see.
<oriba>
Possibly the code will look much better with GADTs
<ggole>
My experience is that GADTs mostly involve pain and suffering.
<oriba>
oh.
mcclurmc has joined #ocaml
dant3_ has quit [Remote host closed the connection]
ulfdoz has joined #ocaml
<ggole>
Don't get me wrong, by all means investigate the feature. I wouldn't hang your hopes on GADTs making your code clearer, though.
<oriba>
hmhh
<oriba>
I'm looking for a better/good representation of comands and results of a language. I tried around with sum types. It's posisble, but sometimes needs many matches. GADTs I did not used so far, I thought they can help. Possibly polymorphic variants would also be a dood idea (don't used them much so far)
<oriba>
s/dood/good/
dant3 has joined #ocaml
sillyotter has joined #ocaml
silly_otter has joined #ocaml
silly_otter has quit [Client Quit]
<ggole>
Arranging sum types for the clearest code can be a bit hit and miss, yeah.
<oriba>
better ideas?
sillyotter has quit [Ping timeout: 240 seconds]
<ggole>
I usually look at the code which is using the types, and try to imagine whether some change would make the code clearer or contain less duplication.
<ggole>
Sometimes that involves changing the type, sometimes writing a helper, etc.
lasts_ has quit [Read error: Connection reset by peer]
lasts_ has joined #ocaml
<oriba>
and you take GADTs not into account in the first place?
<ggole>
I wouldn't use GADTs unless there was a good reason.
introom has joined #ocaml
<oriba>
and what would be a good reason?
wwilly has joined #ocaml
<ggole>
They can give greater type safety in some circumstances. I've actually found it remarkably hard to apply them to any real situation.
<dsheets>
oriba, modeling a type system?
introom5 has quit [Ping timeout: 240 seconds]
<oriba>
hmhm
<oriba>
But thats, what I was doing with the sum types in the pasted code...
<ggole>
Even that can lead to clumsiness.
<oriba>
Maybe the clumsiness is always there
<oriba>
It just looks different with sum types and GADTs?
bjorkintosh has joined #ocaml
<ggole>
Ie, you have type _ term = Int : int -> int term | Bool : bool -> bool term | Pair : 'a * 'b -> ('a * 'b) term and everything looks fine
<ggole>
Then you try to represent arbitrary tuples
<ggole>
| Tuple : 'a array -> 'a array term doesn't work: you need a silly wrapper type, which induces more matching and indirection.
<oriba>
thats the same problem with sum types
<ggole>
With regular sums you just have Tuple of term array
<ggole>
Which is what you want.
<oriba>
but this also needs matching... if you look for a certain variable, you also have to distinguish if it is single value or aggregated (list/array,...)
<ggole>
The problem is that there isn't any (straightforward) way to represent an arbitrary tuple in OCaml's type system: whenever the structure you are trying to represent no longer matches the structure that already exists in the type system, GADTs lose a lot of their appeal.
<oriba>
hmhh :(
avsm has joined #ocaml
<ggole>
There are workarounds, but the code tends to become more complicated rather than simpler in my experience.
ygrek has quit [Ping timeout: 264 seconds]
sheijk has joined #ocaml
introom has quit [Read error: Connection reset by peer]
<oriba>
When I only have the first match in untabgle_apply, I get the following types:
<oriba>
type 'a aggregation_t = Single of 'a | List of 'a list | Array of 'a array
<oriba>
val untangle_apply : ('a -> 'b) -> 'a aggregation_t -> 'b
<oriba>
But when adding the List and/or Array in the match, then I get the type error
<oriba>
"val untangle_apply : ('a -> 'b) -> 'a aggregation_t -> 'b" looks nice to me. Should also work with the other aggregations?!
<ggole>
oriba: the type of each clause is not the same
<ggole>
func x produces type 'b, List.map func l produces type 'b list: those are not the same type.
<oriba>
ah, ok now I see the problem... I need to wrap it again into the aggregation type
<ggole>
Yep.
dant3 has quit [Remote host closed the connection]
michael_lee has quit [Quit: Ex-Chat]
<oriba>
This is what I normaly had in mind (and also used). But it always leads to possibly getting things like List(Array(Single)) stuff - and leads to more matching issues. (Thats what I tried to kick out somehow). Maybe I need s a seperate function that parses the result and rediuces the datatype if needed.
<oriba>
e.g. List(List) could in some cases be redused to List by concattenating; but not always.... depends on the function...
<oriba>
Hmhhh. then each function of my DSL would need to get converter-functions on their side...
tant2n has joined #ocaml
tobiasBora has joined #ocaml
tant2n has quit [Quit: Leaving]
Xenasis has quit [Remote host closed the connection]
Kakadu has quit [Ping timeout: 272 seconds]
avsm has quit [Quit: Leaving.]
avsm has joined #ocaml
avsm has quit [Quit: Leaving.]
swistak35 has quit [Ping timeout: 264 seconds]
ollehar has quit [Ping timeout: 272 seconds]
dant3 has joined #ocaml
dant3 has quit [Read error: Connection reset by peer]
dant3 has joined #ocaml
dant3 has quit [Remote host closed the connection]
dant3 has joined #ocaml
Kakadu has joined #ocaml
wwilly has quit [Quit: This computer has gone to sleep]
ollehar has joined #ocaml
oriba has quit [Quit: oriba]
swistak35 has joined #ocaml
q66_ has joined #ocaml
q66 has quit [Ping timeout: 246 seconds]
avsm has joined #ocaml
tobiasBora has quit [Ping timeout: 272 seconds]
zpe has joined #ocaml
snyp has joined #ocaml
zpe has quit [Remote host closed the connection]
zpe has joined #ocaml
q66_ is now known as q66
zpe has quit [Ping timeout: 264 seconds]
ggole has quit []
tobiasBora has joined #ocaml
angerman has quit [Quit: Gone]
skchrko has quit [Quit: Leaving]
snyp has quit [Quit: K Bye]
Xenasis has joined #ocaml
zpe has joined #ocaml
zpe has quit [Ping timeout: 240 seconds]
tane has quit [Quit: Verlassend]
<Kakadu>
ctypes has type Unsigned.uint8 = UInt8.t and I'm wondering how can I create values of UInt8.t.
<Kakadu>
In what package should I look for UInt8 module?
<adrien>
isn't it inside ctypes?
<adrien>
what does ctypes depend on?
<Kakadu>
unix and bigarray only
<adrien>
bigarray has such a type
<adrien>
but I have no idea how ctypes' is defined
<Kakadu>
Found! thanks
tobiasBora has quit [Ping timeout: 252 seconds]
lopex has joined #ocaml
lopex has quit []
lopex_ has joined #ocaml
lopex_ is now known as lopex
mcclurmc has quit [Remote host closed the connection]
Xenasis has quit [Remote host closed the connection]
Simn has joined #ocaml
zpe has joined #ocaml
zpe has quit [Ping timeout: 240 seconds]
tobiasBora has joined #ocaml
boogie has joined #ocaml
Xenasis has joined #ocaml
kyrylo has joined #ocaml
angerman has joined #ocaml
Kakadu has quit []
angerman has quit [Ping timeout: 240 seconds]
swistak35 has quit [Ping timeout: 240 seconds]
angerman has joined #ocaml
Xenasis has quit [Remote host closed the connection]
boogie has quit [Remote host closed the connection]
smerz_ has joined #ocaml
smerz has joined #ocaml
mcclurmc has joined #ocaml
mcclurmc has quit [Remote host closed the connection]
Xenasis has joined #ocaml
ulfdoz has quit [Ping timeout: 260 seconds]
mcclurmc has joined #ocaml
Arsenik has quit [Remote host closed the connection]
Arsenik has joined #ocaml
angerman has quit [Quit: Gone]
rainbyte has joined #ocaml
mcclurmc has quit [Remote host closed the connection]
sheijk has quit [Ping timeout: 252 seconds]
Xenasis has quit [Remote host closed the connection]
Simn has quit [Ping timeout: 246 seconds]
darkf has joined #ocaml
Arsenik has quit [Remote host closed the connection]
dant3 has quit [Remote host closed the connection]
dant3 has joined #ocaml
oriba has joined #ocaml
sheijk has joined #ocaml
tobiasBora has quit [Quit: Konversation terminated!]
nisstyre has joined #ocaml
avsm has quit [Quit: Leaving.]
dant3 has quit [Remote host closed the connection]
rwmjones has quit [Read error: Operation timed out]
rwmjones has joined #ocaml
<dsheets>
is there something preventing primitive literals at the type level?
<dsheets>
not any operators -- just literals like int and string
ygrek has joined #ocaml
dant3 has joined #ocaml
<dsheets>
specifically, there are sometimes strings that are essentially namespace identifiers and it would be nice to be able to put those into types
madroach has quit [Ping timeout: 252 seconds]
smerz has quit [Ping timeout: 260 seconds]
dant3 has quit [Ping timeout: 264 seconds]
smerz_ has quit [Ping timeout: 272 seconds]
madroach has joined #ocaml
oriba has quit [Read error: Connection reset by peer]
oriba_ has joined #ocaml
NoNNaN has quit [Remote host closed the connection]
Xenasis has joined #ocaml
rwmjones has quit [Read error: Operation timed out]