corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Anyone any good at functional programming?


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 Anyone any good at functional programming?
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
1st Dec 04 at 15:50   View User's Profile U2U Member Reply With Quote

Anyone any good at functional programming in caml light?

I'm majorly stuck... normal programming i.e. C++, Delphi, Pascal, etc is easy - but functional programming in Caml Light is crazy shit and I missed a few too many lectures

Help

Paul J
ed
Member

Registered: 10th Sep 03
User status: Offline
1st Dec 04 at 18:26   View User's Profile U2U Member Reply With Quote

Go read the book fool
Paul_J
Member

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

what book?
John
Member

Registered: 30th Jun 03
User status: Offline
2nd Dec 04 at 00:28   View User's Profile U2U Member Reply With Quote

The big book of functional programming in caml light obv
R Lee
Member

Registered: 15th Aug 03
User status: Offline
2nd Dec 04 at 00:29   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Paul_J
what book?


the bible
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
2nd Dec 04 at 01:37   View User's Profile U2U Member Reply With Quote

quote:
Originally posted by Richard Lee
quote:
Originally posted by Paul_J
what book?


the bible


I'm going to need to pray as I have no idea how the fuck to do this work... everything I type just says error...

bjective Caml version 3.08.0
jective Caml version 3.08.0
let addcomp (a,b)(c,d) = (a+c) + (b+d);;
al addcomp : int * int -> int * int -> int = <fun>
let subcomp (a,b)(c,d) = (a-c) + (b-d);;
al subcomp : int * int -> int * int -> int = <fun>
let mulcomp (a,b)(c,d) = ((a*c)-(b*d)) + ((b*c)+(a*d));;
al mulcomp : int * int -> int * int -> int = <fun>
mulcomp (4,5)(3,5);;
: int = 22
mulcomp (3,4)(2,6);;
: int = 8
addcomp (4,3)(6,4);;
: int = 17
let addcomp (a,b)(c,d) = (a+c),(b+d);;
al addcomp : int * int -> int * int -> int * int = <fun>
addcomp (4,3)(6,4);;
: int * int = (10, 7)
let subcomp (a,b)(c,d) = (a-c),(b-d);;
al subcomp : int * int -> int * int -> int * int = <fun>
subcomp (4,3)(6,4);;
: int * int = (-2, -1)
let add = fun (a,b)(c,d) -> a+b+c+d;;
al add : int * int -> int * int -> int = <fun>
add (4,3)(6,4);;
: int = 17
let addcomp = fun (a,b)(c,d) -> (a+c),(b+d);;
al addcomp : int * int -> int * int -> int * int = <fun>
let subcomp = fun (a,b)(c,d) -> (a-c),(b-d);;
al subcomp : int * int -> int * int -> int * int = <fun>
let mulcomp = fun (a,b)(c,d) -> ((a*c)-(b*d)),((b*c)+(a*d));;
al mulcomp : int * int -> int * int -> int * int = <fun>
mulcomp (4,3)(6,4);;
: int * int = (12, 34)
let divcomp = fun (a,b)(c,d) -> ((((a*c)+(b*d))+((b*c)-(a*d)))/((c*c)+(d*d)));;
al divcomp : int * int -> int * int -> int = <fun>
divcomp (4,3)(6,4);;
: int = 0
divcomp (8,3)(4,3);;
: int = 1
divcomp (19,3)(5,3);;
: int = 1
divcomp (10,6)(5,3);;
: int = 2
divcomp (12,10)(5,1);;
: int = 4
sqrt 5;;
haracters 5-6:
sqrt 5;;
^
his expression has type int but is here used with type float
sqrt 5.6;;
: float = 2.3664319132398464
let abscomp = fun (a,b) -> sqrt((a*a)+(b*b));;
haracters 31-44:
let abscomp = fun (a,b) -> sqrt((a*a)+(b*b));;
^^^^^^^^^^^^^
his expression has type int but is here used with type float
let abscomp = fun (a,b) -> sqrt((a*.a)+.(b*.b));;
al abscomp : float * float -> float = <fun>
abscomp (4,5);;
haracters 8-13:
abscomp (4,5);;
^^^^^
his expression has type int * int but is here used with type float * float
abscomp (4.3,5.6);;
: float = 7.0604532432415406
let abscomp = fun (a,b) -> sqrt((a*.a),(b*.b));;
haracters 31-46:
let abscomp = fun (a,b) -> sqrt((a*.a),(b*.b));;
^^^^^^^^^^^^^^^
his expression has type float * float but is here used with type float
let abscomp = fun (a,b) -> sqrt((a*.a)+.(b*.b));;
al abscomp : float * float -> float = <fun>
abscomp (9.532,5.742);;
: float = 11.127874370246998

bjective Caml version 3.08.0
jective Caml version 3.08.0
let addmoney = fun (po1,sh1,pe1)(po2,sh2,pe2) -> something;;
haracters 49-58:
let addmoney = fun (po1,sh1,pe1)(po2,sh2,pe2) -> something;;
^^^^^^^^^
nbound value something
let value1 = fun (po1,sh1,pe1) -> (po1+sh1,+pe1);;
al value1 : int * int * 'a -> int * 'a = <fun>
value1 (1,2,3);;
: int * int = (3, 3)
let value1 = fun (po1,sh1,pe1) -> (po1+sh1+pe1);;
al value1 : int * int * int -> int = <fun>
let value2 = fun (po2,sh2,pe2) -> (po2+sh2+pe2);;
al value2 : int * int * int -> int = <fun>
let addvalue = fun -> (value1+value2);;
haracters 19-21:
let addvalue = fun -> (value1+value2);;
^^
yntax error
let addvalue = fun (value1+value2);;
haracters 19-20:
let addvalue = fun (value1+value2);;
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let addvalue = (value1+value2);;
haracters 16-22:
let addvalue = (value1+value2);;
^^^^^^
his expression has type int * int * int -> int but is here used with type
int
value1;;
: int * int * int -> int = <fun>
let addvalue = fun (value1,value2) -> value1+value2;;
al addvalue : int * int -> int = <fun>
value1 (1,2,3);;
: int = 6
let value1 = fun (po1,sh1,pe1) -> ((po1*20*12)+(sh1*12)+pe1);;
al value1 : int * int * int -> int = <fun>
value1 (1,2,3);;
: int = 267
let value2 = fun (po2,sh2,pe2) -> ((po2*20*12)+(sh2*12)+pe2);;
al value2 : int * int * int -> int = <fun>
value2 (0,0,5);;
: int = 5
value2(0,2,5);;
: int = 29
let addvalue = value1 + value2;;
haracters 15-21:
let addvalue = value1 + value2;;
^^^^^^
his expression has type int * int * int -> int but is here used with type
int
let addvalue = value1(po1,sh1,pe1) + value2(po2,sh2,pe2);;
haracters 22-25:
let addvalue = value1(po1,sh1,pe1) + value2(po2,sh2,pe2);;
^^^
nbound value po1
let addvalue = value1(po1,sh1,pe1) + value2(po2,sh2,pe2);;
haracters 22-25:
let addvalue = value1(po1,sh1,pe1) + value2(po2,sh2,pe2);;
^^^
nbound value po1
let addvalue = fun (po1,sh1,pe1)(po2,sh2,pe2) -> (((po1*20*12)+(sh1*12)+pe1)+((pol2*20*12)+(sh2*12)+pe2));;
haracters 79-83:
let addvalue = fun (po1,sh1,pe1)(po2,sh2,pe2) -> (((po1*20*12)+(sh1*12)+pe1)+((pol2*20*12)+(sh2*12)+pe2));;
^^^^
nbound value pol2
let addvalue = fun (po1,sh1,pe1)(po2,sh2,pe2) -> (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
al addvalue : int * int * int -> int * int * int -> int = <fun>
addvalue (2,3,4)(3,4,5);;
: int = 1293
5/2;;
: int = 2
1293/240;;
: int = 5
5*240;;
: int = 1200
93/12;;
: int = 7
12*7;;
: int = 84
93-84;;
: int = 9
addvalue (9,11,9)(9,5,4);;
: int = 4525
4525/240;;
: int = 18
18*240;;
: int = 4320
4525-4320;;
: int = 205
205/12;;
: int = 17
12*17;;
: int = 204
205-204;;
: int = 1
let addmoney = addvalue;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
addmoney;;
: int * int * int -> int * int * int -> int = <fun>
addmoney (9,11,9)(9,5,4);;
: int = 4525
let addmoney = addvalue/240;;
haracters 15-23:
let addmoney = addvalue/240;;
^^^^^^^^
his expression has type int * int * int -> int * int * int -> int
ut is here used with type int
let addmoney = addvalue x;;
haracters 24-25:
let addmoney = addvalue x;;
^
nbound value x
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
haracters 115-117:
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let addvalue = ((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
haracters 113-114:
let addvalue = ((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2)));;
haracters 115-116:
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2)));;
^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2);;
haracters 60-61:
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2);;
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let addmoney po1 sh1 pe1 po2 sh2 pe2 =
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
haracters 115-117:
let addvalue = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
haracters 110-112:
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;

let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
haracters 2-5:
# let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
^^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
haracters 110-112:
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2));;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in sum / 240;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
addmoney(2,4,5)(4,5,7);;
: int = 6
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if sum > 12 then sum / 12 else sum;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
addmoney(2,4,5)(4,6,5);;
: int = 6
let rec addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if sum > 12 then sum / 12 else sum;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
addmoney(2,4,5)(4,6,5);;
: int = 6
addmoney(5,6,2)(5,6,2);;
: int = 10
let rec addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
addmoney(5,6,2)(5,6,2);;
: int = 10
addmoney(0,11,1)(0,11,2);;
: int = 1
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
addmoney(0,11,1)(0,11,2);;
: int = 1
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) -> (pound,shill,pence) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
haracters 40-42:
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) -> (pound,shill,pence) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) = (pound,shill,pence) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
haracters 43-48:
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) = (pound,shill,pence) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
^^^^^
nbound value pound
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240 else
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
al addmoney : int * int * int -> int * int * int -> int = <fun>
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
haracters 155-157:
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) = let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240
if (sum-((sum/240)*240)) > 12 then sum / 12 else su;;
haracters 155-157:
if (sum-((sum/240)*240)) > 12 then sum / 12 else su;;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
haracters 46-48:
in if sum > 240 then sum / 240
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in if sum > 240 then sum / 240
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
haracters 160-162:
if (sum-((sum/240)*240)) > 12 then sum / 12 else sum;;
^^
yntax error
let addmoney (po1,sh1,pe1)(po2,sh2,pe2) =
let rec sum = (((po1*20*12)+(sh1*12)+pe1)+((po2*20*12)+(sh2*12)+pe2))
in (Pound(sum),Shil(sum),Pence(sum));;
haracters 125-135:
in (Pound(sum),Shil(sum),Pence(sum));;
^^^^^^^^^^
nbound constructor Pound
let Pound = fun (sum) -> if sum > 240 then sum / 240;;
haracters 4-9:
let Pound = fun (sum) -> if sum > 240 then sum / 240;;
^^^^^
nbound constructor Pound
let pound = fun (sum) -> if sum > 240 then sum / 240;;
haracters 43-52:
let pound = fun (sum) -> if sum > 240 then sum / 240;;
^^^^^^^^^
his expression has type int but is here used with type unit
let pound = fun (x) -> if x > 240 then x / 240;;
haracters 39-46:
let pound = fun (x) -> if x > 240 then x / 240;;
^^^^^^^
his expression has type int but is here used with type unit
let pound = fun x -> if x > 240 then x / 240;;
haracters 37-44:
let pound = fun x -> if x > 240 then x / 240;;
^^^^^^^
his expression has type int but is here used with type unit
let pound (sum) = if sum > 240 then sum / 240;;
haracters 36-45:
let pound (sum) = if sum > 240 then sum / 240;;
^^^^^^^^^
his expression has type int but is here used with type unit
sum;;
haracters 0-3:
sum;;
^^^
nbound value sum
let pound = fun (sum) x -> sum = x
in if sum > 240 then x / 240;;
haracters 46-49:
in if sum > 240 then x / 240;;
^^^
nbound value sum
let pound(sum) x = (sum = x)
in if sum > 240 then x / 240;;
haracters 19-20:
let pound(sum) x = (sum = x
^
yntax error: ')' expected, the highlighted '(' might be unmatched
let pound(sum) = x = sum
in if sum > 240 then x / 240;;
haracters 23-24:
let pound(sum) = sum = x
^
nbound value x
let pound(sum) x = sum = x
in if sum > 240 then x / 240;;
haracters 23-24:
let pound(sum) = sum = x
^
nbound value x
let x = 0;;
al x : int = 0
Characters 5-7:
in if sum > 240 then x / 240;;
^^
yntax error
let x = 0;;
al x : int = 0
let pound(sum) = x in
if sum > 240 then x / 240;;
haracters 29-32:
if sum > 240 then x / 240;;
^^^
nbound value sum
let pound sum = x in
if sum > 240 then x / 240;;
haracters 29-32:
if sum > 240 then x / 240;;
^^^
nbound value sum
let pound sum = x in
if sum > 240 then x / 240;;
haracters 28-31:
if sum > 240 then x / 240;;
^^^
nbound value sum
let pound = fun (sum) = x in
if sum > 240 then x / 240;;
haracters 22-23:
let pound = fun (sum) = x in
^
yntax error
let pound = fun (sum) -> x in
if sum > 240 then x / 240;;
haracters 22-23:
let pound = fun (sum) = x in
^
yntax error
let pound = fun (sum) -> x in
if sum > 240 then x / 240;;
haracters 37-40:
if sum > 240 then x / 240;;
^^^
nbound value sum
let pound (sum) = fun x -> in
if sum > 240 then x / 240;;
haracters 37-40:
if sum > 240 then x / 240;;
^^^
nbound value sum
let pound = fun (sum) -> x in
if sum > 240 then x / 240;;


This is all the shite I have typed in recently, mostly experimenting to try to figure it out - but as soon as I think I have unstood it - it starts throwing up gay errors
R Lee
Member

Registered: 15th Aug 03
User status: Offline
2nd Dec 04 at 01:39   View User's Profile U2U Member Reply With Quote

holy shit

i know you do essay's, but this is truly taking the piss PMSL
Paul_J
Member

Registered: 6th Jun 02
Location: London
User status: Offline
2nd Dec 04 at 01:41   View User's Profile U2U Member Reply With Quote

copied + pasted from my log of caml light ... I've got the biggest head ache and no idea how I'm going to complete my assignment for monday as I still can't get basic stuff to work properly.
John
Member

Registered: 30th Jun 03
User status: Offline
2nd Dec 04 at 01:55   View User's Profile U2U Member Reply With Quote

I am in the same boat in uni. Although i feel you are starting too early. If it was this time on monday morning you would be more like me. Really should start earlier.
John
Member

Registered: 30th Jun 03
User status: Offline
2nd Dec 04 at 01:57   View User's Profile U2U Member Reply With Quote

And i was just thinking i've got a functional programming thing from after xmas. Bastard.
John
Member

Registered: 30th Jun 03
User status: Offline
2nd Dec 04 at 01:58   View User's Profile U2U Member Reply With Quote

Its haskell. And looking at your code there its very similar. If you find the big book of functional programming can you point me in the right direction please

 
New Topic

New Poll

Corsa Sport » Message Board » Off Day » Anyone any good at functional programming? 23 database queries in 0.0138240 seconds