- Jul 30, 2007
- 76
- 0
- 0
I'm doing my programming assignment and I'm stuck on this part.
so this function is supposed to behave like this
# pipe [] 3;;
- : int = 3
# pipe [(fun x-> 2*x);(fun x -> x + 3)] 3 ;;
- : int = 9
# pipe [(fun x -> x + 3);(fun x-> 2*x)] 3;;
- : int = 12
if the list contains functions it will execute them all in order then return int
if there is no function in the list it returns the initial value.
and this is the skeleton given to us and we can edit .... part of the code
let pipe fs =
let f b x = ....... in
let base = ....... in
List.fold_left f base fs
what I tried to do is...
let pipe fs =
let f b x = x b in
let base = fun y -> y in
List.fold_left f base fs
but this had type error.
when I run it on ocaml command line i get
# pipe [(fun x-> 2*x);(fun x -> x + 3)] 3 ;;
This expression has type 'a -> 'a but is here used with type int
I can't figure out what to do so I pass in int for the parameter...
any feed back will be very helpful for me.
thanks in advance.
so this function is supposed to behave like this
# pipe [] 3;;
- : int = 3
# pipe [(fun x-> 2*x);(fun x -> x + 3)] 3 ;;
- : int = 9
# pipe [(fun x -> x + 3);(fun x-> 2*x)] 3;;
- : int = 12
if the list contains functions it will execute them all in order then return int
if there is no function in the list it returns the initial value.
and this is the skeleton given to us and we can edit .... part of the code
let pipe fs =
let f b x = ....... in
let base = ....... in
List.fold_left f base fs
what I tried to do is...
let pipe fs =
let f b x = x b in
let base = fun y -> y in
List.fold_left f base fs
but this had type error.
when I run it on ocaml command line i get
# pipe [(fun x-> 2*x);(fun x -> x + 3)] 3 ;;
This expression has type 'a -> 'a but is here used with type int
I can't figure out what to do so I pass in int for the parameter...
any feed back will be very helpful for me.
thanks in advance.