corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » look what I've been doing the last 6 hours :|


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author look what I've been doing the last 6 hours :|
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
4th Dec 04 at 04:33   View User's Profile U2U Member Reply With Quote

I've been typing this shit into caml light interface the last 6 hours... trying to solve a problem (set for my assignment)...

bjective Caml version 3.08.2
jective Caml version 3.08.2
let rec pwr = fun x n ->
f n < 0 then 1./.pwr x (-n) else
f n = 0 then 1.0 else
*.(pwr x (n-1));;
al pwr : float -> int -> float = <fun>
pwr 4;;
haracters 4-5:
pwr 4;;
^
his expression has type int but is here used with type float
pwr 4 4;;
haracters 4-5:
pwr 4 4;;
^
his expression has type int but is here used with type float
pwr 4.4 4;;
: float = 374.80960000000016
pwr 3.0 4;;
: float = 81.
let money = (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 13-14:
let money = (a,b,c)
^
nbound value a
let money = fun (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 27-29:
in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
haracters 41-48:
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
^^^^^^^
nbound value goodLSD
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
^^^^^^^^^^^
his expression has type int * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
haracters 34-45:
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then a b+1 c-9;;
haracters 38-39:
let money (a,b,c) = if c > 9 then a b+1 c-9;;
^
his expression is not a function, it cannot be applied
let money a b c = a b+1 c;;
haracters 22-23:
let money a b c = a b+1 c;;
^
his expression is not a function, it cannot be applied
let money a b c = a, b+1, c;;
al money : 'a -> int -> 'b -> 'a * int * 'b = <fun>
money 1 2 3;;
: int * int * int = (1, 3, 3)
let money a b c = a, b+1, c-9;;
al money : 'a -> int -> int -> 'a * int * int = <fun>
money 1,2,11;;
: (int -> int -> int * int * int) * int * int = (<fun>, 2, 11)
money 1 2 11;;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) -> (a,b+1,c-9);;
al money : 'a * int * int -> 'a * int * int = <fun>
money (1,2,11);;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3) (4,3,6);;
: int * int * int = (5, 5, 9)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
if c+f > 11 then (a,b+1,c-9);;
haracters 59-60:
if c+f > 11 then (a,b+1,c-9);;
^
nbound value c
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f) ->
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
haracters 41-42:
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
^
nbound value a
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
haracters 51-65:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
^^^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
haracters 8-16:
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
^^^^^^^^
nbound constructor Reduce
let rec reduce = fun x -> x;;
al reduce : 'a -> 'a = <fun>
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
haracters 34-35:
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
^
nbound value x
let money = fun (a,b,c)(d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
let test a b c d = a+b; c+d;;
haracters 19-22:
arning: this expression should have type unit.
let test a b c d = a+b; c+d;;
^^^
al test : int -> int -> int -> int -> int = <fun>
test 1 2 3 4;;
: int = 7
let count = 3;;
al count : int = 3
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if c+f > 11 then b+1 (count-1);;
haracters 77-78:
if c+f > 11 then b+1 (count-1);;
^
his expression is not a function, it cannot be applied
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1;;
haracters 74-81:
if (c+f>11) then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) =
if count = 3 then count-1;;
haracters 42-49:
if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then (count-1);;
haracters 39-48:
let rec test (a,b) = if count = 3 then (count-1);;
^^^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then count-1;;
haracters 39-46:
let rec test (a,b) = if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test a = if count = 3 then count-1 else count;;
al test : 'a -> int = <fun>
test 3;;
: int = 2
let rec test (a,b) = if count = 3 then count-1 else count;;
al test : 'a * 'b -> int = <fun>
test (1,2);;
: int = 2
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;;
haracters 57-97:
....if (c+f>11) then count-1
else count..
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count
else;;
haracters 108-110:
else;;
^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;
else;;
haracters 103-107:
else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count; else;;
haracters 99-103:
else count; else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then if ((c+f) > 11) then count-1 else count;;
haracters 53-92:
if count = 3 then if ((c+f) > 11) then count-1 else count;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if (count = 3) and (c+f > 11) then count-1 else count;;
haracters 50-53:
if (count = 3) and (c+f > 11) then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 and c+f > 11 then count-1 else count;;
haracters 48-51:
if count = 3 and c+f > 11 then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then count-1 else count;;
al money : 'a * 'b * 'c -> 'd * 'e * 'f -> int = <fun>
let rec money (a,b,c) (d,e,f) = if (c+f > 11) then count-1 else count;;
al money : 'a * 'b * int -> 'c * 'd * int -> int = <fun>
money (1,2,3) (1,2,3);;
: int = 3
money (1,2,3) (1,2,12);;
: int = 2
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> count - 1
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count-1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count-1);;
haracters 85-94:
| 1 -> count - 1
^^^^^^^^^
his expression has type int but is here used with type int * int * int
let rec test =
match count with
3 -> count -1;;
haracters 18-51:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count -1..
al test : int = 2
let rec test =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count;;
haracters 18-102:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count..
al test : int = 2
let rec test a =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : 'a -> int = <fun>
test 1;;
: int = 2
let rec test count =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : int -> int = <fun>
test;;
: int -> int = <fun>
test 3;;
: int = 2
test 2;;
: int = 1
let rec test n count =
if count = 0
then 0
else n+1 (count - 1);;
haracters 59-60:
else n+1 (count - 1);;
^
his expression is not a function, it cannot be applied
let rec test n count =
if count = 0 then 0
else count-1;;
al test : 'a -> int -> int = <fun>
test 1;;
: int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else (count-1);;
al test : 'a -> int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else test (count-1);;
haracters 55-69:
else test (count-1);;
^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec test n count =
if count = 0 then 0
else test + n (count-1);;
haracters 55-59:
else test + n (count-1);;
^^^^
his expression has type 'a -> int -> 'b but is here used with type int
let rec sum_until n =
if n = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum_until 5;;
: int = 15
let rec sum_until n =
if count then 0
else n + sum_until (n - 1);;
haracters 28-33:
if count then 0
^^^^^
his expression has type int but is here used with type bool
let rec sum_until n =
if count = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum until 5;;
haracters 0-3:
sum until 5;;
^^^
nbound value sum
sum_until 5;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n =
if count = 0 then 0
else n + sum_until (count - 1);;
al sum_until : int -> int = <fun>
sum_until 3;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count -1);;
haracters 64-84:
else n + sum_until (count -1);;
^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1;;
haracters 74-75:
else n + sum_until (count - 1;;
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1);;
haracters 64-85:
else n + sum_until (count - 1);;
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) count =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 55-56:
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 52-53:
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
| (0,0,0) -> 0
| _ -> 0;;
haracters 64-65:
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
haracters 46-51:
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
^^^^^
nbound value pence
let pwr n = n*n;;
al pwr : int -> int = <fun>
pwr 3;;
: int = 9
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let money = (a+d,b+e,c+f);;
haracters 150-152:
let money = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);;
haracters 150-152:
let total = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
done;
total;;
haracters 155-159:
done;
^^^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
total;;
haracters 160-162:
total;;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f > 11) then (a,b+1,c-12) else if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 213-215:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
haracters 195-197:
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
^^
yntax error
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) c-10 b+1 else
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
(a+d,b+e,c+f);;
haracters 75-77:
if (c+f > 11) then money(a,b,c)(d,e,f)c-10 b+1 else
^^
his expression is not a function, it cannot be applied
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money (a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
money (1,2,3)(3,5,11);;
: int = 2
money;;
: 'a * 'b * int -> 'c * 'd * int -> int = <fun>
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money(a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (c-10) (b+1) else
if (b+e > 19) then money (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
money (1,1,9)(1,2,9);;
: int * int * int = (2, 4, 6)
money (1,1,10)(1,1,10);;
: int * int * int = (2, 3, 8)
money (1,15,1)(1,15,1);;
: int * int * int = (3, 10, 2)
money (15,15,7)(15,15,7);;
: int * int * int = (31, 11, 2)
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) = if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 88-89:
f (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
al moneysub : int * int * int -> int * int * int -> int * int * int = <fun>
moneysub (1,2,3)(0,5,2);;
: int * int * int = (0, 17, 1)
moneysub (10,5,3)(3,25,19);;
: int * int * int = (5, 18, 8)


**********

Basically... I finally got it to work and got 2 working functions...

Add 2 amounts of old style money

let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;

subtract 2 amounts of old style money

let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;

Now I only have 2 more questions left to do

I was very close to killing myself as it was just error after error after error!

I now understand what I was doing wrong and how functional programming works though

Paul J
Nismo
Member

Registered: 12th Sep 02
User status: Offline
4th Dec 04 at 04:59   View User's Profile U2U Member Reply With Quote

for pretyy much the last 6 hours us at work have been playing mini golf and Scorch 2000
Matt H
Member

Registered: 11th Sep 01
Location: South Yorkshire
User status: Offline
4th Dec 04 at 07:42   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
I've been typing this shit into caml light interface the last 6 hours... trying to solve a problem (set for my assignment)...

bjective Caml version 3.08.2
jective Caml version 3.08.2
let rec pwr = fun x n ->
f n < 0 then 1./.pwr x (-n) else
f n = 0 then 1.0 else
*.(pwr x (n-1));;
al pwr : float -> int -> float = <fun>
pwr 4;;
haracters 4-5:
pwr 4;;
^
his expression has type int but is here used with type float
pwr 4 4;;
haracters 4-5:
pwr 4 4;;
^
his expression has type int but is here used with type float
pwr 4.4 4;;
: float = 374.80960000000016
pwr 3.0 4;;
: float = 81.
let money = (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 13-14:
let money = (a,b,c)
^
nbound value a
let money = fun (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 27-29:
in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
haracters 41-48:
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
^^^^^^^
nbound value goodLSD
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
^^^^^^^^^^^
his expression has type int * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
haracters 34-45:
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then a b+1 c-9;;
haracters 38-39:
let money (a,b,c) = if c > 9 then a b+1 c-9;;
^
his expression is not a function, it cannot be applied
let money a b c = a b+1 c;;
haracters 22-23:
let money a b c = a b+1 c;;
^
his expression is not a function, it cannot be applied
let money a b c = a, b+1, c;;
al money : 'a -> int -> 'b -> 'a * int * 'b = <fun>
money 1 2 3;;
: int * int * int = (1, 3, 3)
let money a b c = a, b+1, c-9;;
al money : 'a -> int -> int -> 'a * int * int = <fun>
money 1,2,11;;
: (int -> int -> int * int * int) * int * int = (<fun>, 2, 11)
money 1 2 11;;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) -> (a,b+1,c-9);;
al money : 'a * int * int -> 'a * int * int = <fun>
money (1,2,11);;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3) (4,3,6);;
: int * int * int = (5, 5, 9)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
if c+f > 11 then (a,b+1,c-9);;
haracters 59-60:
if c+f > 11 then (a,b+1,c-9);;
^
nbound value c
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f) ->
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
haracters 41-42:
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
^
nbound value a
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
haracters 51-65:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
^^^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
haracters 8-16:
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
^^^^^^^^
nbound constructor Reduce
let rec reduce = fun x -> x;;
al reduce : 'a -> 'a = <fun>
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
haracters 34-35:
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
^
nbound value x
let money = fun (a,b,c)(d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
let test a b c d = a+b; c+d;;
haracters 19-22:
arning: this expression should have type unit.
let test a b c d = a+b; c+d;;
^^^
al test : int -> int -> int -> int -> int = <fun>
test 1 2 3 4;;
: int = 7
let count = 3;;
al count : int = 3
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if c+f > 11 then b+1 (count-1);;
haracters 77-78:
if c+f > 11 then b+1 (count-1);;
^
his expression is not a function, it cannot be applied
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1;;
haracters 74-81:
if (c+f>11) then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) =
if count = 3 then count-1;;
haracters 42-49:
if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then (count-1);;
haracters 39-48:
let rec test (a,b) = if count = 3 then (count-1);;
^^^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then count-1;;
haracters 39-46:
let rec test (a,b) = if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test a = if count = 3 then count-1 else count;;
al test : 'a -> int = <fun>
test 3;;
: int = 2
let rec test (a,b) = if count = 3 then count-1 else count;;
al test : 'a * 'b -> int = <fun>
test (1,2);;
: int = 2
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;;
haracters 57-97:
....if (c+f>11) then count-1
else count..
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count
else;;
haracters 108-110:
else;;
^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;
else;;
haracters 103-107:
else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count; else;;
haracters 99-103:
else count; else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then if ((c+f) > 11) then count-1 else count;;
haracters 53-92:
if count = 3 then if ((c+f) > 11) then count-1 else count;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if (count = 3) and (c+f > 11) then count-1 else count;;
haracters 50-53:
if (count = 3) and (c+f > 11) then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 and c+f > 11 then count-1 else count;;
haracters 48-51:
if count = 3 and c+f > 11 then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then count-1 else count;;
al money : 'a * 'b * 'c -> 'd * 'e * 'f -> int = <fun>
let rec money (a,b,c) (d,e,f) = if (c+f > 11) then count-1 else count;;
al money : 'a * 'b * int -> 'c * 'd * int -> int = <fun>
money (1,2,3) (1,2,3);;
: int = 3
money (1,2,3) (1,2,12);;
: int = 2
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> count - 1
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count-1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count-1);;
haracters 85-94:
| 1 -> count - 1
^^^^^^^^^
his expression has type int but is here used with type int * int * int
let rec test =
match count with
3 -> count -1;;
haracters 18-51:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count -1..
al test : int = 2
let rec test =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count;;
haracters 18-102:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count..
al test : int = 2
let rec test a =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : 'a -> int = <fun>
test 1;;
: int = 2
let rec test count =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : int -> int = <fun>
test;;
: int -> int = <fun>
test 3;;
: int = 2
test 2;;
: int = 1
let rec test n count =
if count = 0
then 0
else n+1 (count - 1);;
haracters 59-60:
else n+1 (count - 1);;
^
his expression is not a function, it cannot be applied
let rec test n count =
if count = 0 then 0
else count-1;;
al test : 'a -> int -> int = <fun>
test 1;;
: int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else (count-1);;
al test : 'a -> int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else test (count-1);;
haracters 55-69:
else test (count-1);;
^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec test n count =
if count = 0 then 0
else test + n (count-1);;
haracters 55-59:
else test + n (count-1);;
^^^^
his expression has type 'a -> int -> 'b but is here used with type int
let rec sum_until n =
if n = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum_until 5;;
: int = 15
let rec sum_until n =
if count then 0
else n + sum_until (n - 1);;
haracters 28-33:
if count then 0
^^^^^
his expression has type int but is here used with type bool
let rec sum_until n =
if count = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum until 5;;
haracters 0-3:
sum until 5;;
^^^
nbound value sum
sum_until 5;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n =
if count = 0 then 0
else n + sum_until (count - 1);;
al sum_until : int -> int = <fun>
sum_until 3;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count -1);;
haracters 64-84:
else n + sum_until (count -1);;
^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1;;
haracters 74-75:
else n + sum_until (count - 1;;
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1);;
haracters 64-85:
else n + sum_until (count - 1);;
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) count =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 55-56:
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 52-53:
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
| (0,0,0) -> 0
| _ -> 0;;
haracters 64-65:
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
haracters 46-51:
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
^^^^^
nbound value pence
let pwr n = n*n;;
al pwr : int -> int = <fun>
pwr 3;;
: int = 9
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let money = (a+d,b+e,c+f);;
haracters 150-152:
let money = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);;
haracters 150-152:
let total = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
done;
total;;
haracters 155-159:
done;
^^^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
total;;
haracters 160-162:
total;;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f > 11) then (a,b+1,c-12) else if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 213-215:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
haracters 195-197:
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
^^
yntax error
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) c-10 b+1 else
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
(a+d,b+e,c+f);;
haracters 75-77:
if (c+f > 11) then money(a,b,c)(d,e,f)c-10 b+1 else
^^
his expression is not a function, it cannot be applied
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money (a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
money (1,2,3)(3,5,11);;
: int = 2
money;;
: 'a * 'b * int -> 'c * 'd * int -> int = <fun>
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money(a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (c-10) (b+1) else
if (b+e > 19) then money (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
money (1,1,9)(1,2,9);;
: int * int * int = (2, 4, 6)
money (1,1,10)(1,1,10);;
: int * int * int = (2, 3, 8)
money (1,15,1)(1,15,1);;
: int * int * int = (3, 10, 2)
money (15,15,7)(15,15,7);;
: int * int * int = (31, 11, 2)
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) = if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 88-89:
f (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
al moneysub : int * int * int -> int * int * int -> int * int * int = <fun>
moneysub (1,2,3)(0,5,2);;
: int * int * int = (0, 17, 1)
moneysub (10,5,3)(3,25,19);;
: int * int * int = (5, 18, 8)


**********

Basically... I finally got it to work and got 2 working functions...

Add 2 amounts of old style money

let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;

subtract 2 amounts of old style money

let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;

Now I only have 2 more questions left to do

I was very close to killing myself as it was just error after error after error!

I now understand what I was doing wrong and how functional programming works though

Paul J



PGTF for makin us read this
Richie
Member

Registered: 3rd Dec 02
Location: Newport, Wales
User status: Offline
4th Dec 04 at 08:29   View User's Profile U2U Member Reply With Quote

may i say fook that
Dean_H
Member

Registered: 19th May 02
Location: Rhondda Cynon Taff
User status: Offline
4th Dec 04 at 09:56   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
I've been typing this shit into caml light interface the last 6 hours... trying to solve a problem (set for my assignment)...

bjective Caml version 3.08.2
jective Caml version 3.08.2
let rec pwr = fun x n ->
f n < 0 then 1./.pwr x (-n) else
f n = 0 then 1.0 else
*.(pwr x (n-1));;
al pwr : float -> int -> float = <fun>
pwr 4;;
haracters 4-5:
pwr 4;;
^
his expression has type int but is here used with type float
pwr 4 4;;
haracters 4-5:
pwr 4 4;;
^
his expression has type int but is here used with type float
pwr 4.4 4;;
: float = 374.80960000000016
pwr 3.0 4;;
: float = 81.
let money = (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 13-14:
let money = (a,b,c)
^
nbound value a
let money = fun (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 27-29:
in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
haracters 41-48:
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
^^^^^^^
nbound value goodLSD
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
^^^^^^^^^^^
his expression has type int * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
haracters 34-45:
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then a b+1 c-9;;
haracters 38-39:
let money (a,b,c) = if c > 9 then a b+1 c-9;;
^
his expression is not a function, it cannot be applied
let money a b c = a b+1 c;;
haracters 22-23:
let money a b c = a b+1 c;;
^
his expression is not a function, it cannot be applied
let money a b c = a, b+1, c;;
al money : 'a -> int -> 'b -> 'a * int * 'b = <fun>
money 1 2 3;;
: int * int * int = (1, 3, 3)
let money a b c = a, b+1, c-9;;
al money : 'a -> int -> int -> 'a * int * int = <fun>
money 1,2,11;;
: (int -> int -> int * int * int) * int * int = (<fun>, 2, 11)
money 1 2 11;;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) -> (a,b+1,c-9);;
al money : 'a * int * int -> 'a * int * int = <fun>
money (1,2,11);;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3) (4,3,6);;
: int * int * int = (5, 5, 9)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
if c+f > 11 then (a,b+1,c-9);;
haracters 59-60:
if c+f > 11 then (a,b+1,c-9);;
^
nbound value c
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f) ->
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
haracters 41-42:
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
^
nbound value a
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
haracters 51-65:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
^^^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
haracters 8-16:
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
^^^^^^^^
nbound constructor Reduce
let rec reduce = fun x -> x;;
al reduce : 'a -> 'a = <fun>
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
haracters 34-35:
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
^
nbound value x
let money = fun (a,b,c)(d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
let test a b c d = a+b; c+d;;
haracters 19-22:
arning: this expression should have type unit.
let test a b c d = a+b; c+d;;
^^^
al test : int -> int -> int -> int -> int = <fun>
test 1 2 3 4;;
: int = 7
let count = 3;;
al count : int = 3
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if c+f > 11 then b+1 (count-1);;
haracters 77-78:
if c+f > 11 then b+1 (count-1);;
^
his expression is not a function, it cannot be applied
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1;;
haracters 74-81:
if (c+f>11) then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) =
if count = 3 then count-1;;
haracters 42-49:
if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then (count-1);;
haracters 39-48:
let rec test (a,b) = if count = 3 then (count-1);;
^^^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then count-1;;
haracters 39-46:
let rec test (a,b) = if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test a = if count = 3 then count-1 else count;;
al test : 'a -> int = <fun>
test 3;;
: int = 2
let rec test (a,b) = if count = 3 then count-1 else count;;
al test : 'a * 'b -> int = <fun>
test (1,2);;
: int = 2
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;;
haracters 57-97:
....if (c+f>11) then count-1
else count..
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count
else;;
haracters 108-110:
else;;
^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;
else;;
haracters 103-107:
else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count; else;;
haracters 99-103:
else count; else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then if ((c+f) > 11) then count-1 else count;;
haracters 53-92:
if count = 3 then if ((c+f) > 11) then count-1 else count;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if (count = 3) and (c+f > 11) then count-1 else count;;
haracters 50-53:
if (count = 3) and (c+f > 11) then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 and c+f > 11 then count-1 else count;;
haracters 48-51:
if count = 3 and c+f > 11 then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then count-1 else count;;
al money : 'a * 'b * 'c -> 'd * 'e * 'f -> int = <fun>
let rec money (a,b,c) (d,e,f) = if (c+f > 11) then count-1 else count;;
al money : 'a * 'b * int -> 'c * 'd * int -> int = <fun>
money (1,2,3) (1,2,3);;
: int = 3
money (1,2,3) (1,2,12);;
: int = 2
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> count - 1
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count-1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count-1);;
haracters 85-94:
| 1 -> count - 1
^^^^^^^^^
his expression has type int but is here used with type int * int * int
let rec test =
match count with
3 -> count -1;;
haracters 18-51:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count -1..
al test : int = 2
let rec test =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count;;
haracters 18-102:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count..
al test : int = 2
let rec test a =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : 'a -> int = <fun>
test 1;;
: int = 2
let rec test count =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : int -> int = <fun>
test;;
: int -> int = <fun>
test 3;;
: int = 2
test 2;;
: int = 1
let rec test n count =
if count = 0
then 0
else n+1 (count - 1);;
haracters 59-60:
else n+1 (count - 1);;
^
his expression is not a function, it cannot be applied
let rec test n count =
if count = 0 then 0
else count-1;;
al test : 'a -> int -> int = <fun>
test 1;;
: int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else (count-1);;
al test : 'a -> int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else test (count-1);;
haracters 55-69:
else test (count-1);;
^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec test n count =
if count = 0 then 0
else test + n (count-1);;
haracters 55-59:
else test + n (count-1);;
^^^^
his expression has type 'a -> int -> 'b but is here used with type int
let rec sum_until n =
if n = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum_until 5;;
: int = 15
let rec sum_until n =
if count then 0
else n + sum_until (n - 1);;
haracters 28-33:
if count then 0
^^^^^
his expression has type int but is here used with type bool
let rec sum_until n =
if count = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum until 5;;
haracters 0-3:
sum until 5;;
^^^
nbound value sum
sum_until 5;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n =
if count = 0 then 0
else n + sum_until (count - 1);;
al sum_until : int -> int = <fun>
sum_until 3;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count -1);;
haracters 64-84:
else n + sum_until (count -1);;
^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1;;
haracters 74-75:
else n + sum_until (count - 1;;
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1);;
haracters 64-85:
else n + sum_until (count - 1);;
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) count =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 55-56:
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 52-53:
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
| (0,0,0) -> 0
| _ -> 0;;
haracters 64-65:
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
haracters 46-51:
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
^^^^^
nbound value pence
let pwr n = n*n;;
al pwr : int -> int = <fun>
pwr 3;;
: int = 9
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let money = (a+d,b+e,c+f);;
haracters 150-152:
let money = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);;
haracters 150-152:
let total = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
done;
total;;
haracters 155-159:
done;
^^^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
total;;
haracters 160-162:
total;;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f > 11) then (a,b+1,c-12) else if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 213-215:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
haracters 195-197:
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
^^
yntax error
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) c-10 b+1 else
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
(a+d,b+e,c+f);;
haracters 75-77:
if (c+f > 11) then money(a,b,c)(d,e,f)c-10 b+1 else
^^
his expression is not a function, it cannot be applied
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money (a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
money (1,2,3)(3,5,11);;
: int = 2
money;;
: 'a * 'b * int -> 'c * 'd * int -> int = <fun>
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money(a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (c-10) (b+1) else
if (b+e > 19) then money (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
money (1,1,9)(1,2,9);;
: int * int * int = (2, 4, 6)
money (1,1,10)(1,1,10);;
: int * int * int = (2, 3, 8)
money (1,15,1)(1,15,1);;
: int * int * int = (3, 10, 2)
money (15,15,7)(15,15,7);;
: int * int * int = (31, 11, 2)
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) = if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 88-89:
f (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
al moneysub : int * int * int -> int * int * int -> int * int * int = <fun>
moneysub (1,2,3)(0,5,2);;
: int * int * int = (0, 17, 1)
moneysub (10,5,3)(3,25,19);;
: int * int * int = (5, 18, 8)


**********

Basically... I finally got it to work and got 2 working functions...

Add 2 amounts of old style money

let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;

subtract 2 amounts of old style money

let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;

Now I only have 2 more questions left to do

I was very close to killing myself as it was just error after error after error!

I now understand what I was doing wrong and how functional programming works though

Paul J


Long
Martin
Member

Registered: 15th Mar 04
Location: Dumpstable Drives: Aztec Sxi
User status: Offline
   4th Dec 04 at 11:44   View User's Profile U2U Member Reply With Quote

six hours?! it took me three seconds to see that the answer is '7'
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
4th Dec 04 at 12:03   View User's Profile U2U Member Reply With Quote

what answer?
Demo
Member

Registered: 27th Sep 01
Location: south wales Drives: astra sri ecoflex
User status: Offline
4th Dec 04 at 12:47   View User's Profile U2U Member Reply With Quote

fucking essay queen
taj_ryait
Member

Registered: 18th Jan 04
Location: Greater London
User status: Offline
4th Dec 04 at 12:57   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
I've been typing this shit into caml light interface the last 6 hours... trying to solve a problem (set for my assignment)...

bjective Caml version 3.08.2
jective Caml version 3.08.2
let rec pwr = fun x n ->
f n < 0 then 1./.pwr x (-n) else
f n = 0 then 1.0 else
*.(pwr x (n-1));;
al pwr : float -> int -> float = <fun>
pwr 4;;
haracters 4-5:
pwr 4;;
^
his expression has type int but is here used with type float
pwr 4 4;;
haracters 4-5:
pwr 4 4;;
^
his expression has type int but is here used with type float
pwr 4.4 4;;
: float = 374.80960000000016
pwr 3.0 4;;
: float = 81.
let money = (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 13-14:
let money = (a,b,c)
^
nbound value a
let money = fun (a,b,c)
in if c > 9 then (a,b+1,c-9);;
haracters 27-29:
in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) in if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
haracters 24-26:
let money = fun (a,b,c) if c > 9 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
haracters 41-48:
let money = fun (a,b,c) -> if c > 9 then goodLSD(a,b+1,c-9);;
^^^^^^^
nbound value goodLSD
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
haracters 41-52:
let money = fun (a,b,c) -> if c > 9 then (0,b+1,c-9);;
^^^^^^^^^^^
his expression has type int * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
haracters 34-45:
let money (a,b,c) = if c > 9 then (a,b+1,c-9);;
^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let money (a,b,c) = if c > 9 then a b+1 c-9;;
haracters 38-39:
let money (a,b,c) = if c > 9 then a b+1 c-9;;
^
his expression is not a function, it cannot be applied
let money a b c = a b+1 c;;
haracters 22-23:
let money a b c = a b+1 c;;
^
his expression is not a function, it cannot be applied
let money a b c = a, b+1, c;;
al money : 'a -> int -> 'b -> 'a * int * 'b = <fun>
money 1 2 3;;
: int * int * int = (1, 3, 3)
let money a b c = a, b+1, c-9;;
al money : 'a -> int -> int -> 'a * int * int = <fun>
money 1,2,11;;
: (int -> int -> int * int * int) * int * int = (<fun>, 2, 11)
money 1 2 11;;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) -> (a,b+1,c-9);;
al money : 'a * int * int -> 'a * int * int = <fun>
money (1,2,11);;
: int * int * int = (1, 3, 2)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3) (4,3,6);;
: int * int * int = (5, 5, 9)
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
if c+f > 11 then (a,b+1,c-9);;
haracters 59-60:
if c+f > 11 then (a,b+1,c-9);;
^
nbound value c
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f) in
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = fun -> if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f) ->
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 96-98:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) =
let pence = if c+f > 11 then (a,b+1,c-9);;
haracters 72-74:
let pence = if c+f > 11 then (a,b+1,c-9);;
^^
yntax error
let money (a,b,c) (d,e,f) = (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let money = fun (a,b,c) (d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
haracters 41-42:
let pence = fun c f -> if c+f > 11 then (a,b+1,c-11);;
^
nbound value a
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
haracters 51-63:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a,b+1,c-11);;
^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
haracters 51-65:
let pence = fun (a,b,c)(d,e,f) -> if c+f > 11 then (a, b+1, c-11);;
^^^^^^^^^^^^^^
his expression has type 'a * int * int but is here used with type unit
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
haracters 8-16:
let rec Reduce x = fun 0 -> if x > 0 then x-1;;
^^^^^^^^
nbound constructor Reduce
let rec reduce = fun x -> x;;
al reduce : 'a -> 'a = <fun>
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
haracters 34-35:
let rec reduce = fun x -> 0 in if x > 1 then x-1;;
^
nbound value x
let money = fun (a,b,c)(d,e,f) -> (a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
let test a b c d = a+b; c+d;;
haracters 19-22:
arning: this expression should have type unit.
let test a b c d = a+b; c+d;;
^^^
al test : int -> int -> int -> int -> int = <fun>
test 1 2 3 4;;
: int = 7
let count = 3;;
al count : int = 3
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if c+f > 11 then b+1 (count-1);;
haracters 77-78:
if c+f > 11 then b+1 (count-1);;
^
his expression is not a function, it cannot be applied
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1;;
haracters 74-81:
if (c+f>11) then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) =
if count = 3 then count-1;;
haracters 42-49:
if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then (count-1);;
haracters 39-48:
let rec test (a,b) = if count = 3 then (count-1);;
^^^^^^^^^
his expression has type int but is here used with type unit
let rec test (a,b) = if count = 3 then count-1;;
haracters 39-46:
let rec test (a,b) = if count = 3 then count-1;;
^^^^^^^
his expression has type int but is here used with type unit
let rec test a = if count = 3 then count-1 else count;;
al test : 'a -> int = <fun>
test 3;;
: int = 2
let rec test (a,b) = if count = 3 then count-1 else count;;
al test : 'a * 'b -> int = <fun>
test (1,2);;
: int = 2
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;;
haracters 57-97:
....if (c+f>11) then count-1
else count..
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count
else;;
haracters 108-110:
else;;
^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count;
else;;
haracters 103-107:
else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then
if (c+f>11) then count-1
else count; else;;
haracters 99-103:
else count; else;;
^^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then if ((c+f) > 11) then count-1 else count;;
haracters 53-92:
if count = 3 then if ((c+f) > 11) then count-1 else count;;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
his expression has type int but is here used with type unit
let rec money (a,b,c) (d,e,f) =
if (count = 3) and (c+f > 11) then count-1 else count;;
haracters 50-53:
if (count = 3) and (c+f > 11) then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 and c+f > 11 then count-1 else count;;
haracters 48-51:
if count = 3 and c+f > 11 then count-1 else count;;
^^^
yntax error
let rec money (a,b,c) (d,e,f) =
if count = 3 then count-1 else count;;
al money : 'a * 'b * 'c -> 'd * 'e * 'f -> int = <fun>
let rec money (a,b,c) (d,e,f) = if (c+f > 11) then count-1 else count;;
al money : 'a * 'b * int -> 'c * 'd * int -> int = <fun>
money (1,2,3) (1,2,3);;
: int = 3
money (1,2,3) (1,2,12);;
: int = 2
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> count - 1
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count-1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count-1);;
haracters 85-94:
| 1 -> count - 1
^^^^^^^^^
his expression has type int but is here used with type int * int * int
let rec test =
match count with
3 -> count -1;;
haracters 18-51:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count -1..
al test : int = 2
let rec test =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count;;
haracters 18-102:
arning: this pattern-matching is not exhaustive.
ere is an example of a value that is not matched:

...match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count..
al test : int = 2
let rec test a =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : 'a -> int = <fun>
test 1;;
: int = 2
let rec test count =
match count with
3 -> count-1
| 2 -> count-1
| 1 -> count-1
| 0 -> count
| _ -> count;;
al test : int -> int = <fun>
test;;
: int -> int = <fun>
test 3;;
: int = 2
test 2;;
: int = 1
let rec test n count =
if count = 0
then 0
else n+1 (count - 1);;
haracters 59-60:
else n+1 (count - 1);;
^
his expression is not a function, it cannot be applied
let rec test n count =
if count = 0 then 0
else count-1;;
al test : 'a -> int -> int = <fun>
test 1;;
: int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else (count-1);;
al test : 'a -> int -> int = <fun>
test 1 3;;
: int = 2
let rec test n count =
if count = 0 then 0
else test (count-1);;
haracters 55-69:
else test (count-1);;
^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec test n count =
if count = 0 then 0
else test + n (count-1);;
haracters 55-59:
else test + n (count-1);;
^^^^
his expression has type 'a -> int -> 'b but is here used with type int
let rec sum_until n =
if n = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum_until 5;;
: int = 15
let rec sum_until n =
if count then 0
else n + sum_until (n - 1);;
haracters 28-33:
if count then 0
^^^^^
his expression has type int but is here used with type bool
let rec sum_until n =
if count = 0 then 0
else n + sum_until (n - 1);;
al sum_until : int -> int = <fun>
sum until 5;;
haracters 0-3:
sum until 5;;
^^^
nbound value sum
sum_until 5;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n =
if count = 0 then 0
else n + sum_until (count - 1);;
al sum_until : int -> int = <fun>
sum_until 3;;
tack overflow during evaluation (looping recursion?).
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count -1);;
haracters 64-84:
else n + sum_until (count -1);;
^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1;;
haracters 74-75:
else n + sum_until (count - 1;;
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec sum_until n count =
if count = 0 then 0
else n + sum_until (count - 1);;
haracters 64-85:
else n + sum_until (count - 1);;
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c) (d,e,f) =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) count =
match count with
0 -> (a+d,b+e,c+f)
| 1 -> (count - 1)
| 2 -> if (b+e > 19) then (a+1,b-20,c) (count - 1)
| 3 -> if (c+f > 11) then (a,b+1,c-12) (count - 1);;
haracters 85-86:
| 1 -> (count - 1
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 55-56:
(a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
| _ -> (a+b,b+e,c+f);;
haracters 52-53:
match count with (a+d,b+e,12) -> (a+d,b+e+1,c+f-12)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let rec money (a,b,c) (d,e,f) =
match (a+d,b+e,c+f) with
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
| (0,0,0) -> 0
| _ -> 0;;
haracters 64-65:
(a+d,b+e,c+f) -> (a+d,b+e,c+f)
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
haracters 46-51:
let pence (a,b,c)(d,e,f) = if (c+f > 11) then pence = (a,b+1,c-12) else (a,b,c);;
^^^^^
nbound value pence
let pwr n = n*n;;
al pwr : int -> int = <fun>
pwr 3;;
: int = 9
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let money = (a+d,b+e,c+f);;
haracters 150-152:
let money = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);;
haracters 150-152:
let total = (a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
done;
total;;
haracters 155-159:
done;
^^^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
let total = (a+d,b+e,c+f);
total;;
haracters 160-162:
total;;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12);
let shil = if (b+e) > 19 then (a+1,b-20,c);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 138-140:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f > 11) then (a,b+1,c-12) else if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);
(a+d,b+e,c+f);;
haracters 213-215:
(a+d,b+e,c+f);;
^^
yntax error
let money (a,b,c)(d,e,f) =
let pence = if (c+f) > 11 then (a,b+1,c-12) else if (b+e) > 19 then (a+1,b-20,c) else (a+d,b+e,c+f);
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
haracters 195-197:
let shil = if (b+e > 19) then (a+1,b-20,c) else (a+d,b+e,c+f);;
^^
yntax error
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) c-10 b+1 else
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
(a+d,b+e,c+f);;
haracters 75-77:
if (c+f > 11) then money(a,b,c)(d,e,f)c-10 b+1 else
^^
his expression is not a function, it cannot be applied
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money (a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 115-136:
if (b+e > 19) then money(a,b,c)(d,e,f) b-20 a+1 else
^^^^^^^^^^^^^^^^^^^^^
his expression has type int -> 'a but is here used with type int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
money (1,2,3)(3,5,11);;
: int = 2
money;;
: 'a * 'b * int -> 'c * 'd * int -> int = <fun>
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money(a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money(a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money (c-10) (b+1) else
if (b+e > 19) then money (b-20) (a+1) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
haracters 35-176:
...if (c+f > 11) then money(a,b,c)(d,e,f) (c-10) (b+1) else
if (b+e > 19) then money (a,b,c)(d,e,f) (b-20) (a+1) else
(a+d,b+e,c+f)..
his expression has type int * int * int but is here used with type
int -> int -> int * int * int
let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;
al money : int * int * int -> int * int * int -> int * int * int = <fun>
money (1,2,3)(1,2,3);;
: int * int * int = (2, 4, 6)
money (1,1,9)(1,2,9);;
: int * int * int = (2, 4, 6)
money (1,1,10)(1,1,10);;
: int * int * int = (2, 3, 8)
money (1,15,1)(1,15,1);;
: int * int * int = (3, 10, 2)
money (15,15,7)(15,15,7);;
: int * int * int = (31, 11, 2)
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 91-92:
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) = if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 88-89:
f (b-e < 0 then moneysub(a-1,b+20,c)(d,e,f) else
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
haracters 51-59:
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
^^^^^^^^
nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;
al moneysub : int * int * int -> int * int * int -> int * int * int = <fun>
moneysub (1,2,3)(0,5,2);;
: int * int * int = (0, 17, 1)
moneysub (10,5,3)(3,25,19);;
: int * int * int = (5, 18, 8)


**********

Basically... I finally got it to work and got 2 working functions...

Add 2 amounts of old style money

let rec money (a,b,c)(d,e,f) =
if (c+f > 11) then money(a,b+1,c-12)(d,e,f) else
if (b+e > 19) then money (a+1,b-20,c)(d,e,f) else
(a+d,b+e,c+f);;

subtract 2 amounts of old style money

let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;


I Dont understand this section

nbound value moneysub
let rec moneysub (a,b,c)(d,e,f) =
if (c-f < 0) then moneysub(a,b-1,c+12)(d,e,f) else
if (b-e < 0) then moneysub(a-1,b+20,c)(d,e,f) else
if (a-d < 0) then moneysub(0,b,c)(0,e,f)
else (a-d,b-e,c-f);;


Simon
Member

Registered: 24th Apr 03
Location: Oxfordshire
User status: Offline
4th Dec 04 at 13:36   View User's Profile U2U Member Reply With Quote

rather u than me

 
New Topic

New Poll

Corsa Sport » Message Board » Off Day » look what I've been doing the last 6 hours :| 23 database queries in 0.4340930 seconds