Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Pierre Weis <Pierre.Weis@inria.fr>
To: mattias.waldau@abc.se (Mattias Waldau)
Cc: caml-list@inria.fr
Subject: Re: Typing the result of a function
Date: Sat, 25 Nov 2000 16:54:13 +0100 (MET)	[thread overview]
Message-ID: <200011251554.QAA08379@pauillac.inria.fr> (raw)
In-Reply-To: <HDEEKOMJILGEIHIMAPCDKEMJDKAA.mattias.waldau@abc.se> from Mattias Waldau at "Nov 23, 100 11:25:32 pm"

> I know how to type the arguments, and I like to do it, since I will get the
> compile errors directly, not first when I use the function.
> 
> Thus, I typical write a function like
> 
> (* return the column called name *)
> let find (columns:columns) (name:column_type) =
>   List.find ( fun column -> column.data_type = name ) columns.columns
> 
> which has typing
> 
> val find : columns -> column_type -> column = <fun>
> 
> If I use the interactive environment, I see that I get the expected result
> column. I needed to see this, since this is my first use of List.find, and I
> wanted to be sure that it returned the column.
> 
> However, I would have liked to say this already in the definition of find,
> that the result of my function find should be a column. How is this done?
>
> /mattias
> 
> P.s. I like to type, since I think it is belongs to the documentation of the
> code.

I would suggest to let those types in the module interfaces where
you should already have written the documentation of the code then ...

> P.P.s. How to type arguments is not very well described in the
> documentation. I found one example, twice.

Type constraints are simply introduced by a : symbol and should
normally be enclosed into parens (as in your code above). However, you
can use a simpler form to constraint the results of functions, just
write the constraints before the = sign:

let find (columns:columns) (name:column_type) : column =
   List.find ( fun column -> column.data_type = name ) columns.columns

Hope this helps,

Pierre Weis

INRIA, Projet Cristal, Pierre.Weis@inria.fr, http://cristal.inria.fr/~weis/




      reply	other threads:[~2000-11-25 16:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-20 21:05 Missing something in getting C and Ocaml to Work Together Steve Stevenson
2000-11-22 10:06 ` Wolfgang Lux
2000-11-22 20:29 ` Xavier Leroy
2000-11-23 12:56   ` Sven LUTHER
2000-11-23 22:25     ` Typing the result of a function Mattias Waldau
2000-11-25 15:54       ` Pierre Weis [this message]

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=200011251554.QAA08379@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=mattias.waldau@abc.se \
    /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