caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] variant with tuple arg in pattern match?
@ 2001-04-08  0:22 jgm
  0 siblings, 0 replies; 42+ messages in thread
From: jgm @ 2001-04-08  0:22 UTC (permalink / raw)
  To: caml-list

> Type-based compilation strategies such as TAL and FLINT can deal with
> this issue, but at considerable cost in complexity of the compiler and
> execution speed.

Er, you mean TIL :-)  TAL doesn't care which one you choose.

> Frankly, I think there is no point in maintaining the illusion that
> datatype constructors are either nullary (constant) or unary.  The
> only efficient implementation model is N-ary constructors, so let's
> reflect this in the language.

I agree.  Besides, if you're going to go the uniform route, why not
have all constructors be unary?  This always annoyed me in SML.  

> I agree that in an ideal world the syntax of the declaration should
> make this more explicit, e.g. the CamlP4 way ("Foo of int and int"
> vs. "Foo of int * int").  The current "syntactic overloading" of "*"
> in constructor declarations is sometimes misleading, but did make the
> conversion from Caml V3.1 code convenient a long, long time ago...

What's wrong with "Foo of int,int" or "Foo of (int,int)"?

JGM
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 42+ messages in thread
* RE: [Caml-list] variant with tuple arg in pattern match?
@ 2001-04-10 17:33 Dave Berry
  2001-04-10 22:34 ` John Prevost
  0 siblings, 1 reply; 42+ messages in thread
From: Dave Berry @ 2001-04-10 17:33 UTC (permalink / raw)
  To: Frank Atanassow; +Cc: Daniel de Rauglaudre, caml-list

> From: Frank Atanassow [mailto:franka@cs.uu.nl]
> Sent: Tuesday, April 10, 2001 14:51
> 
> When you say "currying" you are talking about a syntactic 
> matter which arises
> due to positional application. When Daniel said that "currying" is
> basic to the lambda-calculus, he was talking about a more fundamental,
> semantic matter.

Daniel did not write the sentence you attribute to him.  He said that
currying is basic to functional programming.  There are many differences
between functional programming and the pure lambda calculus.  Consider:
let-abstraction, the value polymorphism rule, restrictive type systems,
syntax, tuples, records, exceptions, assignment, modules, IO, size of
programs, etc.

As for syntax versus semantics, I nearly wrote "semantic hack", until I
realised that it only works if the syntax also supports it.

> If you look at lambda-calculus from a sufficiently abstract 
> perspective where
> the syntax is immaterial,...

... then you're not talking about functional programming.  

> And how do you define g in the first case if you don't have 
> semantical currying?

Possibly there is some terminological confusion here.  I've only ever
seen "currying" used to mean the encoding of multiple arguments using
higher order functions.  I certainly do not oppose the use of
higher-order functions for other uses, and of course this requires the
building of closures as you describe.

Dave. 
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 42+ messages in thread
* RE: [Caml-list] variant with tuple arg in pattern match?
@ 2001-04-10 17:25 Dave Berry
  2001-04-10 23:16 ` Marcin 'Qrczak' Kowalczyk
  0 siblings, 1 reply; 42+ messages in thread
From: Dave Berry @ 2001-04-10 17:25 UTC (permalink / raw)
  To: Marcin 'Qrczak' Kowalczyk, caml-list

> From: Marcin 'Qrczak' Kowalczyk [mailto:qrczak@knm.org.pl]
> Sent: Tuesday, April 10, 2001 14:12

> It's not a hack. When functions can return functions, there 
> is no need of inventing the concept of multiparameter functions.

>From a theoretical perspective, of course not.  From a programming
perspective, there are several reasons, many of which I gave in my
message.  Others include ease of compilation, and familiarity to
mainstream programmers.

> > In cases where a function is explicitly returning another 
> > (as opposed to
> > just simulating multiple arguments), I think the explicit binding
> > describes what is happening more clearly.
> 
> It's not opposition. This is semantically the same, so there 
> is no need of introducing a syntactic difference.

There are two levels of semantics here.  At the higher level, we have
the behaviour that the programmer is trying to communicate, which
distinguishes returning a function as a result on the one hand from
passing multiple arguments on the other.  The lower level is how this is
encoded in the programming language.  With currying, there is no
difference between the two, so information has been lost.  With multiple
arguments, the distinction is maintained.

> Does map take a function and a list, returning a list, or does it lift
> a function to a function operating on a list? 

Or does it raise a list to a function operating on a function?  Oops,
no, it can't do that, because the person who defined the function didn't
anticipate this use of it.  Time to eta-expand and flip...

Dave.
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 42+ messages in thread
* RE: [Caml-list] variant with tuple arg in pattern match?
@ 2001-04-10 12:17 Dave Berry
  2001-04-10 13:12 ` Marcin 'Qrczak' Kowalczyk
  2001-04-10 13:51 ` Frank Atanassow
  0 siblings, 2 replies; 42+ messages in thread
From: Dave Berry @ 2001-04-10 12:17 UTC (permalink / raw)
  To: Daniel de Rauglaudre, caml-list

You certainly can avoid currying in functional languages.  Currying is a
hack that was created to keep the lambda calculus as simple as possible.
Currying lets the lambda calculus simulate two things:

1. Multiple arguments.  Fine for the calculus, but in any language with
tuples or records we can just write f(x,y), like everybody else.

2. Partial application.  Again, fine for the calculus, but for languages
this fixes the decision of which arguments can be partially applied when
the function is defined, instead of where it is used.  If we define
functions with tuple arguments, we can introduce an explicit syntax for
partial application, e.g. f(_,y).

The explicit syntax is particularly useful for ML, because of the value
polymorphism rule.  In pure functional languages (and SML'90), you can
write:
	let flatten = fold \:: []
In ML, this gives an error (at least at top level), and you have to
eta-expand the definition:
	let sum l = fold \:: [] l
With explicit syntax for partial application, you would write:
	let sum = fold (\::, [], _)

Daniel points out that you will always be able to return a function from
a function.  But currying is a partly syntactic hack; it relies on
function application being notated by juxtaposition.  Without this hack,
you have to write:
	let f = g (x, y)
	f (z)
instead of:
	g x y z
In cases where a function is explicitly returning another (as opposed to
just simulating multiple arguments), I think the explicit binding
describes what is happening more clearly.

Incidentally, using juxtaposition to denote application makes it harder
for the parser to detect some errors.  This makes it more likely that
the user will see a type error where a simpler parse error would have
been more appropriate.  An earlier writer in this thread has already
pointed out that if some arguments are mistakenly omitted in a curried
application, this isn't reported until the point of use (and there might
not even be any uses, if the function is only called for its side
effects).


-----Original Message-----
From: Daniel de Rauglaudre [mailto:daniel.de_rauglaudre@inria.fr]
Sent: Monday, April 09, 2001 8:34
To: caml-list@inria.fr
Subject: Re: [Caml-list] variant with tuple arg in pattern match?


Hi,

On Mon, Apr 09, 2001 at 08:23:40AM +0200, Mattias Waldau wrote:

> If so, I don't think that curried syntax is something good.

I agree with your arguments, but... but you cannot avoid currification
in functional languages.

Ok, all your functions take non curried parameters, but how do you write
a function which returns a function? If it is:

   let f x = fun y -> blahblah

ok, you can write it:

   let f (x, y) = blahblah

But, how do you transform it if it is:

   let f x = blahblahblah...; blah blah blah; fun y -> blah blah

Currification is inside functional languages, you cannot decide to
ignore it.

And in OCaml, currified functions are more efficient (mmm... Xavier,
tell us if I am wrong). Besides, if you don't apply all arguments, you
get typing errors (in most cases), anyway.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives:
http://caml.inria.fr
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 42+ messages in thread
* [Caml-list] variant with tuple arg in pattern match?
@ 2001-04-04 11:04 Chris Hecker
  2001-04-04 18:47 ` Alain Frisch
  2001-04-04 19:18 ` Patrick M Doane
  0 siblings, 2 replies; 42+ messages in thread
From: Chris Hecker @ 2001-04-04 11:04 UTC (permalink / raw)
  To: caml-list


I can't find anything about this in the docs, faq, or list archives.

I expected ii to be bound to the int * int tuple (1,2) in this pattern match:

# type foo = Foo of int * int;;
type foo = Foo of int * int
#   match Foo (1,2) with Foo ii -> ii ;;
Characters 23-29:
The constructor Foo expects 2 argument(s),
but is here applied to 1 argument(s)


This works:

# match Foo (1,2) with Foo _ -> () ;;
- : unit = ()

But I can't get an "as" clause to work, either:

# match Foo (1,2) with Foo ((_,_) as ii) -> ii ;;
Characters 21-38:
The constructor Foo expects 2 argument(s),
but is here applied to 1 argument(s)

But, even if the "as" worked, it's messy compared to the top method.
 
Chris

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2001-04-17 17:33 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-04-08  0:22 [Caml-list] variant with tuple arg in pattern match? jgm
  -- strict thread matches above, loose matches on Subject: below --
2001-04-10 17:33 Dave Berry
2001-04-10 22:34 ` John Prevost
2001-04-10 17:25 Dave Berry
2001-04-10 23:16 ` Marcin 'Qrczak' Kowalczyk
2001-04-10 12:17 Dave Berry
2001-04-10 13:12 ` Marcin 'Qrczak' Kowalczyk
2001-04-10 21:26   ` Bruce Hoult
2001-04-10 22:34     ` John Prevost
2001-04-10 13:51 ` Frank Atanassow
2001-04-04 11:04 Chris Hecker
2001-04-04 18:47 ` Alain Frisch
2001-04-04 19:18 ` Patrick M Doane
2001-04-04 19:36   ` Chris Hecker
2001-04-04 19:49     ` Daniel de Rauglaudre
2001-04-05  8:19       ` Christian RINDERKNECHT
2001-04-04 19:49     ` Patrick M Doane
2001-04-06 13:52   ` Xavier Leroy
2001-04-07  1:42     ` Patrick M Doane
2001-04-07  6:44       ` Daniel de Rauglaudre
2001-04-07  7:42     ` Fergus Henderson
2001-04-08 19:45       ` Pierre Weis
2001-04-08 20:37         ` Charles Martin
2001-04-08 23:57         ` Brian Rogoff
2001-04-09  0:22           ` Alain Frisch
2001-04-09 16:07             ` Pierre Weis
2001-04-10  8:23               ` Michel Mauny
2001-04-10  9:14                 ` Xavier Leroy
2001-04-10 10:09                   ` Michel Mauny
2001-04-10 10:44                 ` reig
2001-04-10 11:32                   ` Michel Mauny
2001-04-10 11:47                     ` reig
2001-04-10 12:10                       ` reig
2001-04-10 12:35                         ` Michel Mauny
2001-04-10 12:49                         ` Marcin 'Qrczak' Kowalczyk
2001-04-09  6:23           ` Mattias Waldau
2001-04-09  7:34             ` Daniel de Rauglaudre
2001-04-09 15:57           ` Pierre Weis
2001-04-10  9:07             ` Sven LUTHER
2001-04-09  8:20         ` Christian RINDERKNECHT
2001-04-10  2:54         ` Patrick M Doane
2001-04-10 19:04           ` John Max Skaller

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).