systems has quit [Read error: 104 (Connection reset by peer)]
CybeRDukE has joined #ocaml
bk_ has quit ["leaving"]
bk_ has joined #ocaml
bk_ has quit [Client Quit]
bk_ has joined #ocaml
bk_ has quit ["leaving"]
CybeRDukE is now known as CybeR[away]
bk_ has joined #ocaml
docelic has joined #ocaml
pahan has joined #ocaml
pahan has left #ocaml []
pahan has joined #ocaml
pahan is now known as Pahan
mattam_ has joined #ocaml
<Pahan>
Hi! Could somebody explain how to compile a "hello world" Python extension module with pycaml? I know nothing about Ocaml, but if this thing works, I'll start learning.
mattam has quit [Read error: 60 (Operation timed out)]
async has quit ["Lost terminal"]
systems has joined #ocaml
Xcalibor has joined #ocaml
<Xcalibor>
greetings
<Xcalibor>
english? français?
<systems>
arabic
<Xcalibor>
bad...
<systems>
>:(
<Xcalibor>
I got a question, maybe someone can help me
<systems>
arabic is the best
<Xcalibor>
but I don't know it... just a few words...
<Xcalibor>
it looks beautiful, though
<systems>
:)
<Xcalibor>
I am trying to define a function that accepts either an int or a float... how can I do that?
<Xcalibor>
because let foo 'a n = ... ;; doesn't work when I try to match the type of n...
<Xcalibor>
it's just a kind of generic let foo n = n + 1;;
<Xcalibor>
but not specifying which + or +. to use until I know which type is n
<Xcalibor>
can you help me? I cannot find anything on the documentation...
<systems>
well, i am no ocaml expert, but i met this before
<systems>
one solution is to define ur own type
<systems>
or use object oriented features
<systems>
both work fine
<systems>
this is a logical problem not a technical one
<systems>
or so i think
<Xcalibor>
been looking at that... the Num module should work, but how do I coerce the function parameter to type num? there's no constructor I can use (or so it seems)
<systems>
i learned about it from the paul graham iterator genetor test or whatever
<Xcalibor>
yes, that's what I'm trying to solve :)
<systems>
define a translator/convertion function
<systems>
it will be easy
<systems>
num_to_float or num_to_int
<Xcalibor>
I sent him solutions in several languages (none updated on the website, actually) and I'm trying to prove Ocaml can do it, and also that Tcl can do it (that's proving hard, though)
<systems>
very straighht foward
<Xcalibor>
mmm...
<Xcalibor>
let me see...
<systems>
but i like the OO solution better
<systems>
i dont remember how i did it really, but oop with ocaml is very good
<Xcalibor>
did you solve it?
<systems>
in a way yes
<Xcalibor>
i'd like to see that solution if you can find it on your archives
<systems>
:(
<systems>
it was very simple, as i told you i am not good , in ocaml or even programming in general
<systems>
i just read a lil about oo in ocaml, and used basic features
<Xcalibor>
let foo (n : num) = n +/ 1 ;;
<Xcalibor>
This expression has type int but is here used with type Num.num
<Xcalibor>
that's the thing, how do I coerce the 1 to num?
<systems>
int_to_num function ?
<Xcalibor>
nopes
<systems>
if ur problem is identifyin what the user entered that is another problem
<systems>
user enter a string
<Xcalibor>
yup
<systems>
read the string and use regexp to know to what it qualify
<Xcalibor>
is there any way of doing introspection on types, or something?
<systems>
and they use a string_to_num transltor
<Xcalibor>
how can I check the type 'a?
<systems>
intrispection is for objects i guess
<systems>
to know what methods they support
<Xcalibor>
let foo 'a n = if 'a is int then n + 1 else n +. 1.0 ;;
<Xcalibor>
that doesn't work :-(
<systems>
create a number type
<systems>
create functions that will add .. sub .. divide numbers and number
<systems>
s
<systems>
within a program you have control over types
<systems>
i think
<Xcalibor>
# type number = Int of int | Float of float ;;
<Xcalibor>
type number = Int of int | Float of float
<Xcalibor>
# let foo 'a n = match 'a with Int -> n + 1 | Float -> n +. 1.0 ;;
<Xcalibor>
Syntax error
<Xcalibor>
how do I match the type of n? that's the quid of the problem...
<systems>
this wont work
<Xcalibor>
i know, the copiler told me :-P
<systems>
Int a -> a + 1
<systems>
but it still wont work,
<Xcalibor>
mmm
<systems>
you cant return a random type
<systems>
you must creat an add_num functions and use it
<systems>
to add numbers to numbers
<Xcalibor>
ok, but how do I discriminate between the integer and the floating cases of type number?
<systems>
easy with the constructor
<systems>
Int or Float
<Xcalibor>
?
<Xcalibor>
care to elaborate?
<systems>
okay, i told you i am not good
<systems>
but you look a newbie too so i am not wasting ur time
<systems>
:)
<systems>
now Int + Float , will return what ?
<systems>
Float or Int
<systems>
its ur type, you made it, you decide
noss has joined #ocaml
<systems>
I would say Float
<Xcalibor>
mmm... dunno... the compiler finds int
<Xcalibor>
let foo n = match n with Int n -> n + 1 | Float n -> n +. 1.0 ;;
<Xcalibor>
This expression has type float but is here used with type int
<systems>
no i would make it like this
<systems>
i did not try it yet
<Xcalibor>
go ahead, I have the repl handy
<systems>
let add_num a b = match a,b with Int x, Int y -> Int (x+y) | Flot x, Int y -> Float (x+ float_of_int y) | etc...
<systems>
match every possible case
<Xcalibor>
mmmm... I see
<systems>
i guess all in all its will be only 4 case
<systems>
and the int promotion to float is implied
srv has quit [Read error: 54 (Connection reset by peer)]
<Xcalibor>
mmm... i can't seee that promotion
<systems>
yes you can
srv has joined #ocaml
<Xcalibor>
:-/
<systems>
let add_num a b = match a,b with Int x, Int y -> Int (x+y) | Float x, Int y -> Float (x +. float_of_int y) | Int x , Float y -> Float ( float_of_int x +. y) | Float x , Float y -> Float (x+.y)
<systems>
check it
<systems>
try it :)
<Xcalibor>
Unbound constructor Float
<systems>
let a , b = Int 100 , Float 100. in in add_num a b ;;
<systems>
type numbers = Int of int | Float of float ;;