deech_99 | 1 Dec 01:29
Favicon

Pattern matching on arrays

Ocaml offers pattern matching on arrays, but it doesn't seem to behave
like list pattern-matching.

For instance, the following, where 'x' is the first element and '_' is
the rest of the array doesn't work:
# match [|1;2;3|] with [|x;_|] -> x;;

Characters 0-33:

match [|1;2;3|] with [|x;_|] -> x;;

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Warning P: this pattern-matching is not exhaustive.

Here is an example of a value that is not matched:

[| |]

Exception: Match_failure ("", 100, -408).

Is there some way to do this in Ocaml?
-deech

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Yahoo! Groups

Cats Group

Join a group for

cat owners like you

.

__,_._,___
pisethkem | 27 Nov 09:52
Favicon
Gravatar

Re: beginner question about typing

--- In ocaml_beginners <at> yahoogroups.com, "ben.aurel" <ben.aurel <at> ...> wrote:
>
> hi
> I make another attempt with ocaml and it seems like it doesn't fit my
> brain yet.
>
> ---
> let max a b =
> if a > b then a else b
> ;;
>
> print_newline (max 3 5) ;;
>
> ---
>
> The error message is the following:
> This expression has type int but is here used with type unit
>
>
> If tried several things like 'int max' or casting like 'then int a',
> but it doesn't work.
>
> What am I doing wrong here?
> thanks
> ben
>

you miss the case when a = b

let max a b =
if a <= b then b else a;;

print_int (max 3 5);;

piseth kem

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New business?

Get new customers.

List your web site

in Yahoo! Search.

Get in Shape

on Yahoo! Groups

Find a buddy

and lose weight.

.

__,_._,___
pisethkem | 25 Nov 14:23
Favicon
Gravatar

Re: How quit?

--- In ocaml_beginners <at> yahoogroups.com, "murray2004eisenberg"
<murray <at> ...> wrote:
>
> How do I quit/exit/end an interactive Objective Caml session? I don't
> see this mentioned in the getting started docs.
>

#quit;;
or

exit 0; (* for return 0, same as unix command : true *)
exit 1; (* same as unix command : false *)

(* exit can be used in both interpreter and *.ml code *)

or

^D (Control + D) to send EOF to the interpreter.

---------
pisethkem

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

Check out the

Y! Groups blog

Stay up to speed

on all things Groups!

.

__,_._,___
David Lloyd | 24 Nov 08:15
Favicon

Re: Re: How quit?


Howdy,

bash-3.2$ ocaml
Objective Caml version 3.10.2

# exit 1;;
bash-3.2$ echo $?
1
bash-3.2$ ocaml
Objective Caml version 3.10.2

# exit 50;;
bash-3.2$ echo $?
50

The $? variable is the value that the terminated process returned.

DSL

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New business?

Get new customers.

List your web site

in Yahoo! Search.

Yahoo! Groups

Going Green Zone

Learn to go green.

Save energy. Save the planet.

.

__,_._,___
deech_99 | 23 Nov 22:47
Favicon

Re: How quit?

--- In ocaml_beginners <at> yahoogroups.com, "murray2004eisenberg"
<murray <at> ...> wrote:
>
> How do I quit/exit/end an interactive Objective Caml session? I don't
> see this mentioned in the getting started docs.
>

Use the exit method. In the toplevel type:
# exit 1;;

I am not sure what the number after 'exit' does. The exit function is
defined as:
# exit ;;
- : int -> 'a = <fun>

-deech

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New business?

Get new customers.

List your web site

in Yahoo! Search.

Yahoo! Groups

Going Green Zone

Learn to go green.

Save energy. Save the planet.

.

__,_._,___
Dario Teixeira | 21 Nov 16:55
Favicon

Re: Dynlink with C++ source

Hi,

Thanks for the reply. In the meantime I managed to track down
the problem. Remember that I was using ocamlmklib to automate
the generation of the libraries:

blahcaml.cma: blahtex_stubs.o blahcaml.cmo
ocamlmklib -verbose -o blahcaml -oc blahcaml -cclib -lstdc++ $+

These are the actions taken by ocamlmklib:

+ gcc -shared -o ./dllblahcaml.so blahtex_stubs.o -L/home/dario/.godi/lib -Wl,-rpath,/home/dario/.godi/lib
+ ar rc ./libblahcaml.a blahtex_stubs.o; ranlib ./libblahcaml.a
+ ocamlc -a -o blahcaml.cma blahcaml.cmo -dllib -lblahcaml -cclib -lblahcaml -ccopt -L/home/dario/.godi/lib -ccopt -Wl,-rpath,/home/dario/.godi/lib -cclib -lstdc++

The problem is that ocamlmklib does not pass the -cclib -lstdc++
parameters to the first invocation of gcc. When I do it manually
then everything works. I'm filing this as a bug.

On a side note: how is the path /home/dario/.godi/lib obtained?
Sure, I can run `ocamlc -where` and remove the last two directories,
but I'm guessing there's a cleaner way, right?

Cheers,
Dario

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Ads on Yahoo!

Learn more now.

Reach customers

searching for you.

Yahoo! Groups

Cat Zone

Connect w/ others

who love cats.

.

__,_._,___
marlenemiller71 | 20 Nov 23:57
Favicon

Re: let binding ()

> In both cases, the reason is that exhaustiveness checking is based
> only on the type of the expression, not on its value.

Is it correct to explain let-binding for this syntax

let <pattern> = <expression1> in <expression2>

as the type inference mechanism computes type T1 of <pattern> and type
T2 of <expression1> inferring the type of variables in <pattern> using
T2, and then T1 must be the same as T2?

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Health Groups

for people over 40

Join people who are

staying in shape.

.

__,_._,___
marlenemiller71 | 20 Nov 00:09
Favicon

Re: let binding ()

>
> The warning tells you that your constants are from types with
multiple values.
> The value "()" of the type "unit" is the only value of that type so
the
> pattern "()" is exhaustive (matches the only value of that type).
In
> contrast, the type "int" contains more values than just "0", so the
> pattern "0" is not exhaustive.
>
> However, constants are just a special case of this. Any patterns
that cover
> all of the values of a type will satisfy OCaml even if they do not
contain
> any identifiers to be bound:
>
> [] | _::_
>
> None | Some _
>
> let ignore _ = ()
>
> and so on.

The value of g() is []. Why doesn't [] match g()?

> > Here is an example of a value that is not matched:
> > _::_
> > let [] = g();;
> > ^^

The value of h() is 0. Why doesn't 0 match h()?

> > Here is an example of a value that is not matched:
> > 1
> > let 0 = h();;
> > ^

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New web site?

Drive traffic now.

Get your business

on Yahoo! search.

Yahoo! Groups

Going Green Zone

Resources for a greener planet.

Resources for a greener you.

.

__,_._,___
nicoletta triolo | 18 Nov 16:39

Re: Obj.magic

Thanks very much.
I'm studying OcamlP3L system and in its source there is a large use of Obj.magic, so I wanted to know something deeper about it.

Bye,
nicoletta
--- Mar 18/11/08, Dario Teixeira <darioteixeira <at> yahoo.com> ha scritto:
Da: Dario Teixeira <darioteixeira <at> yahoo.com>
Oggetto: Re: "ocaml_beginners"::[] Obj.magic
A: ocaml_beginners <at> yahoogroups.com
Data: Martedì 18 novembre 2008, 16:25

Hi,

> I can't find exhaustive documentation about this

> function. Could somebody explain me its specification?

The first rule of Obj.magic is that you do not talk about

Obj.magic... On a more serious note, Obj.magic is used to

"magically" overrule the type system, allowing you to do

a low-level cast of a type into another. As an example,

try this code in the top-level:

let foo : float = Obj.magic 1;;

Note that this is not a safe type-casting. In fact, on my

machine the above example causes a segfault.

While gurus can certainly find situations where Obj.magic is

indeed useful, I reckon it's almost certain that if you think

you might need Obj.magic, then there must be something wrong

with your design or you are trying to do things which are not

possible within the Ocaml type system.

Cheers,

Dario Teixeira











Unisciti alla community di Io fotografo e video, il nuovo corso di fotografia di Gazzetta dello sport:
http://www.flickr.com/groups/iofotografoevideo

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
Search Ads

Get new customers.

List your web site

in Yahoo! Search.

Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Special K Group

on Yahoo! Groups

Join the challenge

and lose weight.

.

__,_._,___
silviu andrica | 17 Nov 15:34
Favicon

Proof of multi-threaded application.

Hello,
I am very new to Ocaml, this is my first day, and I wanted to know
if it is possible to prove correctness of a multi-threaded application
written in Ocaml.
Basically, I want to check that a multi-threaded implementation of an
algorithm that detects cycles in a dynamically changing graph, actually
detects the cycles. Also, the algorithm prevents previously detected
cycles from happening by not allowing certain edges to be added. And I
want to check that this property also holds.

Thank you and I hope you can help me,
Silviu ANDRICA.

[Non-text portions of this message have been removed]

__._,_.___
Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

New business?

Get new customers.

List your web site

in Yahoo! Search.

Yahoo! Groups

Dog Group

Connect and share with

dog owners like you

.

__,_._,___
deech_99 | 14 Nov 22:17
Favicon

Converting Bison Parser to Ocamlyacc?

Recent Activity
Visit Your Group
Yahoo! Finance

It's Now Personal

Guides, news,

advice & more.

Need traffic?

Drive customers

With search ads

on Yahoo!

Special K Group

on Yahoo! Groups

Join the challenge

and lose weight.

.

__,_._,___

Gmane