<jeddhaberstro>
Hi, I'm just starting Ocaml, and I've run into a snag. What is wrong with line 3 of this? http://pasteall.org/1746/ocaml
<jeddhaberstro>
This expression has type 'a list but is here used with type int
<vixey>
this line | [] -> 0
<vixey>
is a number
<vixey>
1 + x :: incrementList xs;; is a list
<jeddhaberstro>
oh, I see
<vixey>
they should be the same thing
<vixey>
so make | [] -> []
<jeddhaberstro>
| [] -> []
<jeddhaberstro>
gotcha :)
<jeddhaberstro>
Thanks
<jeddhaberstro>
Does the ocaml interpreter and compiler care about line endings? Is that why it told me the error was on line 3?
landonf has joined #ocaml
<mfp>
jeddhaberstro: neither the toplevel nor the compilers care about line endings (or extra whitespaces in general); the type error _was_ on line 3
<jeddhaberstro>
k
<mfp>
jeddhaberstro: btw. just only use ;; in the toplevel typically
<mfp>
s/just/you/
<jeddhaberstro>
ok. I haven't really gotten to the point to knowing what ;; does.
asmanur has joined #ocaml
<mfp>
it's mainly used in the toplevel to indicate the end of a "phrase"
<mfp>
i.e. ;; signals the end of the expression to be evaluated, allowing you to enter several lines at once (unlike, say, ghci, IIRC)
<mfp>
you can also use ;; in .ml files to delimit a phrase, as in let foo () = print_endline "foo";; foo ()
<jeddhaberstro>
ok
<mfp>
but normally, you'd do let foo () = print_endline "foo" let () = foo ()
<jeddhaberstro>
not that that makes much sense right now :)
<mfp>
-> the compiler knows the prev phrase is finished when it sees the second let () = ...
<jeddhaberstro>
ah
<asmanur>
mfp: in the toplevel you can't evaluate several instruction by seperating them by a ";;" (just the first gets evaluated)
<jeddhaberstro>
ok
<jeddhaberstro>
making more sense :)
<mfp>
asmanur: did I say so? :)
<asmanur>
not exactly :)
<mfp>
for the sake of clarity, "several lines at once" referred to a phrase with several lines, not several phrases
<asmanur>
oh, yes I read "several phrases at once"
<mfp>
jeddhaberstro: there's another advantage of doing let () = <expr>; the compiler will verify that <expr> evaluates to (), so it will help you catch partial applications
<jeddhaberstro>
what does () mean?
<mfp>
jeddhaberstro: let foo a b = a + b;; foo 1 -> silent error let foo a b = a + b let () = foo 1 -> error
<mfp>
jeddhaberstro: () is the only value of type "unit"
<mfp>
think of it as "void"
<jeddhaberstro>
yeah, ok :)
<vixey>
why are you learning ocaml?
<jeddhaberstro>
To learn a functional language
<jeddhaberstro>
for fun mainly
<vixey>
ok great
<jeddhaberstro>
why?
_THEGOD has joined #ocaml
<_THEGOD>
lols camels .
<_THEGOD>
what the hell is camel ?
<vixey>
lol
<vixey>
_THEGOD: As is no doubt already displayed on your screen, ocaml is a programming language
<_THEGOD>
does it hawe a compiler ?
<_THEGOD>
or where it works?
<vixey>
_THEGOD: You should read the channel topic when you enter a channel on IRC
<vixey>
both your questions are answered by it
<_THEGOD>
ok .
<_THEGOD>
thanks anyway.
<_THEGOD>
one last question .
<_THEGOD>
on which platform it created ?
<_THEGOD>
i mean source of camel .
<_THEGOD>
asm / c/ c++ /perl ?
<vixey>
ocaml
<_THEGOD>
you mean ocaml created using ocaml ?
<mfp>
_THEGOD: the compiler and the stdlib are written in OCaml; parts of the runtime are written in C and assembly
_THEGOD has left #ocaml []
jeddhaberstro has quit []
landonf has quit []
jeddhaberstro has joined #ocaml
msandin has joined #ocaml
asmanur has quit [Remote closed the connection]
^authentic has joined #ocaml
tomh has joined #ocaml
authentic has quit [Read error: 110 (Connection timed out)]
^authentic is now known as authentic
ecc_ has joined #ocaml
ecc has quit [Read error: 110 (Connection timed out)]
Linktim_ has quit ["Quitte"]
filp has joined #ocaml
ygrek has quit [Remote closed the connection]
filp has quit ["Bye"]
szell` has joined #ocaml
r0bby has quit [Read error: 104 (Connection reset by peer)]
<jeddhaberstro>
if n = 0 then 1 else (x * (pow x n-1));;
<jeddhaberstro>
the recursion never stops, but I have a base condition there..
<flux>
precedency
<flux>
applications binds more tightly than operators
<jeddhaberstro>
so, reverse the x * pow?
<flux>
x * (pow x (n - 1))
<jeddhaberstro>
ah, thanks :)
<vixey>
oh that means you can drop another pair
<vixey>
x * pow x (n - 1)
r0bby has joined #ocaml
<flux>
and even further, the parenthesis after else
<flux>
unless that's what you meant :)
<jeddhaberstro>
Eh, i wasn't sure how Ocaml would handle, so I thought it would be safer to use them :P
GustNG has quit [Read error: 104 (Connection reset by peer)]
<flux>
yoric[dt], how would one type a function similar to List.map with the catch-library?
<Yoric[DT]>
flux: not tonight, too tired :)
<Yoric[DT]>
But tomorrow, I'll discuss that with pleasure.
<flux>
I just remembered that I hadn't read the ml2008.pdf, so maybe I'll just do that now :)
<flux>
good night
<Yoric[DT]>
:)
<flux>
after a brief look, though, it doesn't appear to touch that particular issue
<flux>
(maybe I actually need to _read_ it :-))
crawfordcomeaux has quit []
landonf has joined #ocaml
<landonf>
If I have method M, which accepts a single function argument F, and returns the value of that function, is there any way to allow M to be polymorphic rather than monomorphic? (eg, accept different return types for parameter F)
<flux>
object method foo : 'a.'a -> 'a = fun a -> a end
<flux>
however those types are never automatically inferred, which can be a pain
<flux>
well, it's not a direct answer to your questoin, but as I understand it, it can be easily modified to match it
<Smerdyakov>
landonf, also, both method names and arguments must begin with lowercase letters, so "M" and "F" were bad examples.
<landonf>
flux: Thanks, I'll play with it.
<landonf>
Smerdyakov: Just trying to be concise =)
thelema has joined #ocaml
Snark has quit ["Ex-Chat"]
<landonf>
method private tx : 'a . (Postgresql.connection -> 'a) -> 'a = fun f -> ...
<landonf>
Cool, works. Thanks!
Yoric[DT] has quit ["Ex-Chat"]
msandin has quit ["Leaving."]
coucou747 has quit [Read error: 104 (Connection reset by peer)]
Axioplase_ has quit [Read error: 104 (Connection reset by peer)]