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.

.

__,_._,___
Jake Donham | 20 Nov 00:30

Re: let binding ()

On Wed, Nov 19, 2008 at 3:09 PM, marlenemiller71
<marlenemiller71 <at> yahoo.com> wrote:

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

In both cases, the reason is that exhaustiveness checking is based
only on the type of the expression, not on its value. So the value of
g() is [], but its type is 'a list, which includes values other than
[]; the value of h() is 0, but its type is int, which includes values
other than 0.

However, the type of f() is unit, which includes only the value ().
Therefore the match is exhaustive.

Does that help?

Jake

__._,_.___
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.

Everyday Wellness

on Yahoo! Groups

Find groups that will

help you stay fit.

.

__,_._,___
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.

.

__,_._,___
Jon Harrop | 21 Nov 01:57
Favicon

Re: let binding ()

On Thursday 20 November 2008 22:57:13 marlenemiller71 wrote:
> > 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?

Essentially, yes. Note that "T1 must be the same as T2" should strictly be "T1
is unified with T2".

I found it very instructive to implement a simple type inferencer in OCaml, to
understand how type inference works. That gives you a much better idea of how
to interpret type errors when things go wrong in OCaml as well.

--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

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

It's Now Personal

Guides, news,

advice & more.

Yahoo! Groups

Everyday Wellness Zone

Check out featured

healthy living groups.

All-Bran

Day 10 Club

on Yahoo! Groups

Feel better with fiber.

.

__,_._,___
marlenemiller71 | 21 Nov 06:30
Favicon

Re: let binding ()

> I found it very instructive to implement a simple type inferencer in
OCaml, to
> understand how type inference works. That gives you a much better
idea of how
> to interpret type errors when things go wrong in OCaml as well.

Ok.

__._,_.___
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

Learn to go green.

Save energy. Save the planet.

.

__,_._,___
marlenemiller71 | 20 Nov 01:19
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. So the value
of
> g() is [], but its type is 'a list, which includes values other than
> []; the value of h() is 0, but its type is int, which includes
values
> other than 0.
>
> However, the type of f() is unit, which includes only the value ().
> Therefore the match is exhaustive.
>
> Does that help?

Yes it does help. Thank you Jon and Jake.

Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
_::_

The warning says _::_ is not matched, i.e., the values represented by
_::_ (that might be the value of f() because of its type) are not
matched by [].

__._,_.___
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

Stay healthy

and discover other

people who can help.

.

__,_._,___
Jon Harrop | 20 Nov 02:04
Favicon

Re: let binding ()

On Wednesday 19 November 2008 23:09:21 marlenemiller71 wrote:
> > any identifiers to be bound:
> >
> > [] | _::_
> >
> > None | Some _
> >
> > let ignore _ = ()
> >
> > and so on.
>
> The value of g() is [].

The value of g() is not available to the static type checker at compile time.

> Why doesn't [] match g()?

It does.

You are not seeing a run-time match failure. You are seeing a warning from the
static type checker at compile time stating that it has not been able to
prove that it is safe to remove run-time checks from the generated code.

However, your use of the top-level makes the distinction difficult to see. Put
the program in a file:

$ cat >a.ml
let g() = []
let [] = g()

Compile it and note the compile-time warning:

$ ocamlc a.ml -o a
File "a.ml", line 2, characters 4-6:
Warning P: this pattern-matching is not exhaustive.
Here is an example of a value that is not matched:
_::_

Run it and note that the match does not actually fail:

$ ./a
$

--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e

__._,_.___
Recent Activity
Visit Your Group
Give Back

Yahoo! for Good

Get inspired

by a good cause.

Y! Toolbar

Get it Free!

easy 1-click access

to your groups.

Yahoo! Groups

Start a group

in 3 easy steps.

Connect with others.

.

__,_._,___
marlenemiller71 | 20 Nov 01:35
Favicon

Re: let binding ()

> > The value of g() is [].
>
> The value of g() is not available to the static type checker at
compile time.
>
> > Why doesn't [] match g()?
>
> It does.
>
> You are not seeing a run-time match failure. You are seeing a
warning from the
> static type checker at compile time stating that it has not been
able to
> prove that it is safe to remove run-time checks from the generated
code.
>
> However, your use of the top-level makes the distinction difficult
to see. Put
> the program in a file:
>
> $ cat >a.ml
> let g() = []
> let [] = g()
>
> Compile it and note the compile-time warning:
>
> $ ocamlc a.ml -o a
> File "a.ml", line 2, characters 4-6:
> Warning P: this pattern-matching is not exhaustive.
> Here is an example of a value that is not matched:
> _::_
>
> Run it and note that the match does not actually fail:
>
> $ ./a
> $
>
> --
> Dr Jon Harrop, Flying Frog Consultancy Ltd.
> http://www.ffconsultancy.com/?e
>

Ok, I did that. Very helpful. Thank you.

__._,_.___
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

Learn to go green.

Save energy. Save the planet.

.

__,_._,___

Gmane