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.

.

__,_._,___
Till Crueger | 27 Nov 10:22

Re: Re: beginner question about typing

On Thu, 27 Nov 2008 09:52:18 +0100, pisethkem <pisethkem <at> yahoo.com> wrote:

>> let max a b =
>>     if a > b then a else b
>> ;;
>>
>> print_newline (max 3 5) ;;
[snip]
> you miss the case when a = b
>
> let max a b =
> if a <= b then b else a;;
>
> print_int (max 3 5);;

Please don't confuse beginners.... There is no "case missing" in the above  
example. The only Problem was with the print_newline instead of the  
print_int...

The max functions you gave and he gave are completyl identical as can be  
proven by some simple transformations, like
!(a > b) <=> a <= b
and
if !x then a else b <=> if x then b else a

Apart from that the case a = b is even more irrelevant because in that  
case it does not matter if you return a or b...

Greetings,
   Till

------------------------------------

Archives up to December 31, 2007 are also downloadable at http://www.connettivo.net/cntprojects/ocaml_beginners/
The archives of the very official ocaml list (the seniors' one) can be found at http://caml.inria.fr
Attachments are banned and you're asked to be polite, avoid flames etc.Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/ocaml_beginners/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/ocaml_beginners/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:ocaml_beginners-digest <at> yahoogroups.com 
    mailto:ocaml_beginners-fullfeatured <at> yahoogroups.com

<*> To unsubscribe from this group, send an email to:
    ocaml_beginners-unsubscribe <at> yahoogroups.com

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/


Gmane