caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Roberto Di Cosmo <roberto@dicosmo.org>
To: Ivan Gotovchits <ivg@ieee.org>
Cc: Andreas Rossberg <rossberg@mpi-sws.org>,
	Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>,
	OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] Equality between abstract type definitions
Date: Fri, 25 Oct 2013 14:35:17 +0200	[thread overview]
Message-ID: <20131025123517.GA21960@voyager> (raw)
In-Reply-To: <878uxhd62p.fsf@golf.niidar.ru>

Thanks Ivan,
       the potential confusion between type annotations
in the code and type specifications in module interfaces
is a very good point.

Writing

 let f : 'a -> 'a = fun x -> x+1 

will just boil down to defining 

 val f : int -> int = <fun>

On the other side, declaring 

 val f : 'a -> 'a 

in a module signature actually *requires* the implementation
to be at least as generic as 'a -> 'a, so a definition
let f = fun x -> x+1 in the body will not work.

Nevertheless, I would say that the difference is pretty
easy to grasp, as soon as one explains that specifications
are only introduced in modules signatures, with the val
keyword.

One may want to introduce type specifications in the code
like in Haskell, but I am not sure that il will be much
better for newbies... : let's write some code similar
to the above one

succ :: a -> a
succ n = n+1

here is the system's answer

    No instance for (Num a)
      arising from a use of `+'
    In the expression: n + 1
    In an equation for `succ': succ n = n + 1

Is this really more new-user friendly?

--
Roberto

 

On Fri, Oct 25, 2013 at 01:59:26PM +0400, Ivan Gotovchits wrote:
> Roberto Di Cosmo <roberto@dicosmo.org> writes:
> 
> >
> > I am curious to know why you consider this a pitfall: if it is
> > not what people expect, it is probably because nobody explained
> > their meaning to them properly, and I am quite interested in
> > understanding how to explain this better.
> >
> 
> I think that people expect that an expression:
> 
> ```
>   let a : int = b 
> ```
> 
> is a declaration that value `a` has type int (Just like C'ish 
> `int a = b;`). But, indeed, it should be understood as a type
> constraint. Thus the following, will be readily accepted by the
> type checker (because we «constrain» a to be anything):
> 
> ```
>   let a : 'a = 12
> ```
> 
> The root of misunderstanding, I think, lies in that the same syntax is
> used for type annotations and value specifications. Consider the
> following example:
> 
> ```
>    module T : sig
>     val sum: 'a -> 'a -> 'a
>    end = struct
>     let sum: 'a -> 'a -> 'a = 
>         fun x y -> x + y
>    end
> ```
> 
> It looks like that the value sum has the same type in the module
> specification and in the module implementation. So if compiler accepts
> definition, it should accept that it conforms to the specification. 
> 
> Indeed, it's rather intuitional - this types do look the same!
> 
> So, I think, that it should be clarified by someone, who knows OCaml and
> English much better than me, what is the difference between this two
> cases. And it would be great if it will be described in the manual,
> too. 
> 
> 
> 
> 
> -- 
>          (__) 
>          (oo) 
>    /------\/ 
>   / |    ||   
>  *  /\---/\ 
>     ~~   ~~   
> ...."Have you mooed today?"...

-- 
Roberto Di Cosmo
 
------------------------------------------------------------------
Professeur               En delegation a l'INRIA
PPS                      E-mail: roberto@dicosmo.org
Universite Paris Diderot WWW  : http://www.dicosmo.org
Case 7014                Tel  : ++33-(0)1-57 27 92 20
5, Rue Thomas Mann       
F-75205 Paris Cedex 13   Identica: http://identi.ca/rdicosmo
FRANCE.                  Twitter: http://twitter.com/rdicosmo
------------------------------------------------------------------
Attachments:
MIME accepted, Word deprecated
      http://www.gnu.org/philosophy/no-word-attachments.html
------------------------------------------------------------------
Office location:
 
Bureau 3020 (3rd floor)
Batiment Sophie Germain
Avenue de France
Metro Bibliotheque Francois Mitterrand, ligne 14/RER C
-----------------------------------------------------------------
GPG fingerprint 2931 20CE 3A5A 5390 98EC 8BFC FCCA C3BE 39CB 12D3                        

  parent reply	other threads:[~2013-10-25 12:35 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-24 22:57 Peter Frey
2013-10-24 23:23 ` Jacques Garrigue
2013-10-25  6:44   ` Andreas Rossberg
2013-10-25  8:29     ` Roberto Di Cosmo
2013-10-25  9:59       ` Ivan Gotovchits
2013-10-25 11:09         ` Gabriel Scherer
2013-10-25 14:24           ` Andreas Rossberg
2013-10-25 20:32             ` Yaron Minsky
2013-10-25 20:44               ` Jacques Le Normand
2013-10-26  1:08                 ` Norman Hardy
2013-10-26  5:28                   ` Jacques Garrigue
2013-10-27 12:16               ` Andreas Rossberg
2013-10-27 12:56                 ` Yaron Minsky
2013-10-27 14:28                   ` Gabriel Scherer
2013-10-27 14:43                     ` Yaron Minsky
2013-10-27 15:25                       ` Gabriel Scherer
2013-10-27 15:41                         ` Yaron Minsky
2013-10-25 12:35         ` Roberto Di Cosmo [this message]
2013-10-25 12:45           ` Jonathan Protzenko
2013-10-25 13:20             ` Roberto Di Cosmo
2013-10-25 14:03       ` Andreas Rossberg
2013-10-26  9:07         ` oleg
2013-10-26 14:11           ` Didier Remy
2013-10-26 17:32         ` Didier Remy
2013-10-27 12:07           ` Andreas Rossberg
2013-10-27 14:10             ` Roberto Di Cosmo
2013-10-28  3:30     ` Jacques Garrigue

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20131025123517.GA21960@voyager \
    --to=roberto@dicosmo.org \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    --cc=ivg@ieee.org \
    --cc=rossberg@mpi-sws.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).