<lowks>
does the 'Leaf->0' means it setting the Leaf variable to 0 ?
<Kinners>
function pat1 -> expr1 | pat2 -> expr2 | ... patn -> exprn, evaluates to a function that takes one argument and does the matching
<lowks>
so in that function what does the 'Leaf->0' do ?
<Kinners>
if that argument is a Leaf, the result is 0
<lowks>
so if it meets up with a Leaf argument it will give a result of 0 ?
<lowks>
okay ..
<lowks>
i see how the program works ... but then i dunno how they map real life on to this program =(
<lowks>
that has been my problem all along =((
<Kinners>
let rec fact = function 0 -> 1 | n -> n * fact (n - 1);;
<Kinners>
put that into the toplevel
<lowks>
done
<Kinners>
#trace fact;;
<lowks>
the funny thing about ocaml is that if i write a function like that
<lowks>
trace fact;;
<lowks>
Unbound value trace
<Kinners>
#trace fact is a toplevel directive, trace fact is a function call
<Kinners>
then, fact 10;;
<lowks>
# trace fact;;
<lowks>
Unbound value trace
<lowks>
# fact 10;;
<lowks>
- : int = 90
<lowks>
#
<Kinners>
I mean literally type "#trace fact;;" :)
<lowks>
with the "#" ?
<Kinners>
yes
<lowks>
# fact 10;;
<lowks>
fact <-- 10
<lowks>
fact <-- 9
<lowks>
fact <-- 8
<lowks>
fact <-- 7
<lowks>
fact <-- 6
<lowks>
fact <-- 5
<lowks>
fact <-- 4
<lowks>
fact <-- 3
<lowks>
fact <-- 2
<lowks>
fact <-- 1
<lowks>
fact <-- 0
<lowks>
fact --> 1
<lowks>
fact --> 1
<lowks>
fact --> 2
<lowks>
fact --> 6
<lowks>
fact --> 24
<Kinners>
yeah I know what it prints :)
<lowks>
fact --> 120
<lowks>
fact --> 720
<lowks>
fact --> 5040
<lowks>
fact --> 40320
<lowks>
fact --> 362880
<lowks>
fact --> 3628800
<lowks>
hehe
<lowks>
what does that mean now ?
<lowks>
dun understand it =(
<Kinners>
that's showing the recursion, a left arrow shows the function being called with a value, right arrow is the function returning a value
<lowks>
why does trace need a "#" infront of it ?
<lowks>
what other commands are there ?
<Kinners>
look at the ocaml docs (for the ocaml command)
<lowks>
okay
<lowks>
i really like the way ocaml does recursion
<lowks>
confusing at first
<lowks>
but cool once understood
<Kinners>
now if you try fact (-1);; you'll get an error
<lowks>
stack overflow
<lowks>
# type 'a btree=
<lowks>
Node of 'a*'a btree*'a btree
<lowks>
| Leaf;;
<lowks>
what does that '*' denote here ?
<Kinners>
that's the type for tuples, ("foobar",Leaf,Leaf)
<lowks>
so if it's a list it will be something like :
<lowks>
#type 'a btree=
<lowks>
Node of 'a::'a btree::'a btree ??
<Kinners>
no..
<Kinners>
type in 1, [1,2;3,4];;
<lowks>
?
<Kinners>
type it in, and see the type it prints
<lowks>
oh
<lowks>
# 1, [1,2;3,4];;
<lowks>
- : int * (int * int) list = (1, [(1, 2); (3, 4)])
<lowks>
why is it int*(int*int) ??
<lowks>
i remember '::' is for deconstructing a list tho
<lowks>
hmmm
<Kinners>
:: is for constructing lists, and a comma for constructing tuples
<Kinners>
maybe operator is a better term than constructor for :: and ',', I dunno
<lowks>
then how come i can't write 'Node of 'a::'a btree ..' ?
<Kinners>
firstly, all elements in a list must be of the same type
<lowks>
oh
<lowks>
so can't do stuff like 'a ... 'b
<Kinners>
and the type expression is seperate from how you make a value of that type
<lowks>
okay ...
<Kinners>
so if you have an int list, you can make it with [1;2;3], [1] @ [2;3], 1 :: 2 :: 3 :: [], etc.
<lowks>
how do i write the type constructor for it ?
<Kinners>
for what?
<lowks>
i mean a type that creates a list
<Kinners>
type ilist = int list and illist = ilist list;;
<Kinners>
let foo:illist = [[1];[2];[3;4]];;
<lowks>
what is that 'and' key word for anyway ?
<Kinners>
you have the two type expressions, then you bind the value to foo and tell it that you want it as the illist type (without the :illist the type of foo would be an int list list)
<Kinners>
for recursive type definitions, if they were to reference each other, in this case it's just so it can be on one line :)
polin8 has quit ["Now _that's_ a good cup of coffee."]
polin8 has joined #ocaml
<lowks>
Kinners: for functions in functions .... what exactly does the keyword
<lowks>
'in' do ?
<Kinners>
let this name be bound to that value in this scope
<lowks>
so the 'in' is for scope ?
async has quit ["Lost terminal"]
walters has joined #ocaml
<Kinners>
basically
<walters>
hi. is there an easy way to push back a character onto a standard stream?
<walters>
i wrote my own little thing which looks like type buffered_inchannel = (in_channel * char option ref);;
<walters>
but as i copy this from project to project i just think there must be an easier way
<walters>
or...any suggestions for an easier way to parse a data stream which looks like <int> <string to newline>\n[<float> <float> .... <float>] ?
<Kinners>
use peeking maybe?
wax has quit [Remote closed the connection]
<walters>
how do i peek?
<walters>
oh, i see, Stream.peek
<walters>
hm, no...
wax has joined #ocaml
lament has quit ["LOOSE TEETH DON'T NEED MY HELP"]
Kinners has left #ocaml []
<lowks>
wow
<lowks>
the for loops have 'to' and 'down to'
<lowks>
cool !!
lament has joined #ocaml
<lowks>
what is the 'sig' keyword for ?
<lowks>
what does a 'let function=...' mean ??
<walters>
let function x = ... creates a new function
<walters>
Objective Caml version 3.06
<walters>
# Str.regexp;;
<walters>
Reference to undefined global `Str'
<walters>
any ideas?
<walters>
oh, i have to make a new toplevel.
<walters>
hm.
lament has quit ["MUD IS NOT ONE OF THE 4 FOOD GROUPS"]
walters has quit ["I like core dumps"]
pnou has joined #ocaml
giedi has joined #ocaml
<giedi>
hey
two-face has joined #ocaml
two-face has quit ["Client exiting"]
giedi has quit ["Client Exiting"]
docelic|sleepo is now known as docelic
Kinners has joined #ocaml
malc_ has joined #ocaml
malc_ has left #ocaml []
malc_ has joined #ocaml
two-face has joined #ocaml
two-face has quit ["Client exiting"]
Vincenz has joined #ocaml
two-face has joined #ocaml
Vincenz_ has joined #ocaml
Vincenz has quit [Read error: 104 (Connection reset by peer)]
foxster has quit [Read error: 104 (Connection reset by peer)]
Vincenz_ is now known as Vincenz
xmkl is now known as smkl
<Vincenz>
hmm
<Vincenz>
ocamllex seems to be missing some things that sml-lex has
<Vincenz>
(not that I know shit about sml)
<Vincenz>
does ocamlyacc support the %change directive?
<two-face>
don't know
Kinners has left #ocaml []
malc_ has quit ["malc_ has no reason"]
two-face has left #ocaml []
mattam has quit [Read error: 60 (Operation timed out)]
mattam has joined #ocaml
__DL__ has joined #ocaml
_DL_ has quit [Read error: 110 (Connection timed out)]
archie_sihir has quit [Remote closed the connection]
TachYon26 has joined #ocaml
two-face has joined #ocaml
<Vincenz>
hmm
<Vincenz>
in ocamlyacc can you use something like...
<Vincenz>
LPAREN (exp SEMICOLON)* RPAREN ?
<Vincenz>
or is that too complex?
<Vincenz>
or wait
<Vincenz>
LPAREN exp (SEMICOLON exp)* RPAREN ?
two-face has left #ocaml []
<Vincenz>
question about ocamlyacc
<Vincenz>
how do you define custome types
<Vincenz>
like...for example pos
mattam has quit [Read error: 104 (Connection reset by peer)]
mattam has joined #ocaml
platypus has joined #ocaml
TachYon26 has quit [Remote closed the connection]
axolotl has joined #ocaml
lowks has quit [Read error: 104 (Connection reset by peer)]
lowks has joined #ocaml
wax has quit [Read error: 113 (No route to host)]
stefp has quit [Remote closed the connection]
stefp has joined #ocaml
foxster has joined #ocaml
wax- has joined #ocaml
two-face has joined #ocaml
two-face has left #ocaml []
axolotl has quit [Read error: 110 (Connection timed out)]
wax- has quit [Read error: 60 (Operation timed out)]
wax- has joined #ocaml
cbcbcb has joined #ocaml
<cbcbcb>
can anybody tell me the ocaml equivalent of SML "fun hd x::xs = x"?
mattam has quit [Remote closed the connection]
mattam has joined #ocaml
<cbcbcb>
or can anybody suggest a good online ocaml tutorial?
* Riastradh
points at ocaml.org -> the O'Caml Manual -> the first section.
<Riastradh>
fun hd x::xs = x
<Riastradh>
can be translated to OCaml as:
<Riastradh>
let hd (x :: xs) = x;;
<cbcbcb>
thanks
polin8 has quit ["Lost terminal"]
<Riastradh>
Is there a multidimensional array module?
<Riastradh>
Oh, matrices in the Array module.
<Smerdyakov>
Do you just want this as a runtime optimization?
<Riastradh>
No, I just wanted to see if there was already a library of operations on multidimensional arrays so I wouldn't have to write my own.
<Riastradh>
Of course, there aren't many matrix operations in the Array module, I suppose.
Smerdyakov has quit []
stefp has quit [Read error: 110 (Connection timed out)]
stefp has joined #ocaml
foxster has quit [Read error: 104 (Connection reset by peer)]
foxster has joined #ocaml
foxster has quit [Read error: 104 (Connection reset by peer)]
polin8 has joined #ocaml
<Riastradh>
Can constructors take records? -- like: type foo = Foo of { a : b; c : d };;
foxster has joined #ocaml
cbcbcb has quit []
docelic has quit [Read error: 104 (Connection reset by peer)]
polin8 has quit ["Lost terminal"]
polin8 has joined #ocaml
polin8 has quit [Client Quit]
polin8 has joined #ocaml
docelic has joined #ocaml
Vincenz has quit []
jao has joined #ocaml
__DL__ has quit [Remote closed the connection]
Smerdyakov has joined #ocaml
polin8 has quit [Read error: 104 (Connection reset by peer)]
docelic is now known as docelic|sleepo
polin8 has joined #ocaml
docelic|sleepo is now known as docelic
polin8 has quit [Read error: 54 (Connection reset by peer)]