wilfredh has quit [Quit: Connection closed for inactivity]
sspreitz9 has joined #ocaml
sspreitz9 has quit [Remote host closed the connection]
Jesin has joined #ocaml
Jesin has quit [Quit: Leaving]
zlsyx has joined #ocaml
zlsyx_ has joined #ocaml
zlsyx has quit [Ping timeout: 272 seconds]
zlsyx_ has quit [Quit: Leaving...]
ygrek__ has quit [Remote host closed the connection]
ygrek__ has joined #ocaml
warriors has joined #ocaml
ygrek__ has quit [Ping timeout: 272 seconds]
MadcapJake has joined #ocaml
mfp has quit [Ping timeout: 240 seconds]
hunboy5 has joined #ocaml
hunboy5 has quit [Remote host closed the connection]
maximjaffe has joined #ocaml
quipa_ has quit [Ping timeout: 268 seconds]
Jesin has joined #ocaml
tormen_ has joined #ocaml
tormen has quit [Ping timeout: 272 seconds]
maximjaffe has quit [Ping timeout: 240 seconds]
cthuluh has quit [Ping timeout: 245 seconds]
cthuluh has joined #ocaml
pierpal has quit [Quit: Poof]
pierpal has joined #ocaml
dsp has joined #ocaml
<dsp>
hey ocaml ppl. can you explain smth to me because i feel like an utter moron? i am trying lear ocaml and define just an iterative fibonacci. so i have a let fibiter a b n = if n > smth then a else fibiter b a+b n+1 in...
<dsp>
i keep getting a This expression has type 'a -> 'b but an expression of type int was expected. is it complaining because my return type from fibiter is ambiguous?
<dsp>
sorry i'm a schemer trying to start with ocaml
metreo has left #ocaml [#ocaml]
<warriors>
you probably need let rec fitbiter
<warriors>
you need to declare a function recursive in ocaml
<warriors>
or ml langs in general
<warriors>
ocaml have shadowing
<warriors>
so without recursive declaration the system will try to look first for a previous definition of fibiter
<warriors>
or so i think
<warriors>
i am not an ocaml expert
<warriors>
but ocaml is the best
<dsp>
1b1i finally did it like that... i don't know how valid ocaml this is
<dsp>
let fib1 n =
<dsp>
in
<dsp>
| (a,b,c) when c > n -> a
<dsp>
let rec fibiter = function
<dsp>
| (a, b, c) -> fibiter(b,a+b,c+1)
<dsp>
fibiter(1,1,0);;
<dsp>
this looks quite elegant so i think it's ok for a first approach. but here is my question now... is the tupling of the arguments necessary here? or could i have smth like | a b c when c > n -> and call like fibiter b a+b c+1 ?
<dsp>
i tried it and failed initially but it could also be a pebkac.
<warriors>
just use an if statement then
<warriors>
if c > n then a else fibitier b (a+b) (c+1)
<dsp>
so that's how was failing originally, check this out
<dsp>
let fib2 n =
<dsp>
let rec fibiter a b c =
<dsp>
if c > n then a else fibiter b a+b c+1
<dsp>
in
<dsp>
fibiter(1,1,0);;
<dsp>
this fails with type 'a -> 'b etc...
<warriors>
that last fitibier should be fibiter 1 1 0
<warriors>
dont tuple it
<dsp>
oh sorry yes
<warriors>
does it work now
<dsp>
no :)
<warriors>
bleh
<dsp>
here warriors , since you share my pain this is exactly what i have been trying