caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Snd question
@ 2005-08-15 22:05 Anu Engineer
  2005-08-15 22:41 ` [Caml-list] " Matt Gushee
  0 siblings, 1 reply; 19+ messages in thread
From: Anu Engineer @ 2005-08-15 22:05 UTC (permalink / raw)
  To: caml-list

Hi All,

Please forgive me if my question is very naïve, I am very new to Ocaml. I was wondering why snd returns an  error when I use it with more than 2 elements, why not return the rest of the list when I apply to something larger than a pair ?

Regards
Anu
-Gnothi seauton


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

* Re: [Caml-list] Snd question
  2005-08-15 22:05 Snd question Anu Engineer
@ 2005-08-15 22:41 ` Matt Gushee
  2005-08-16  8:08   ` sejourne kevin
  2005-08-16 13:17   ` skaller
  0 siblings, 2 replies; 19+ messages in thread
From: Matt Gushee @ 2005-08-15 22:41 UTC (permalink / raw)
  To: caml-list

Anu Engineer wrote:

 > Please forgive me if my question is very naïve, I am very new to 
Ocaml. I was

 > wondering why snd returns an  error when I use it with more than 2 
elements, why

 > not return the rest of the list when I apply to something larger than 
a pair ?


Your question shows your misunderstanding: snd operates on tuples, not 
lists. If it did operate on lists the length wouldn't matter, because 
length doesn't affect the type of a list. I.e.

     [ 1; 2; 3; ... n ]

is of type 'int list' whether it has 4 elements or 40,000,000. Whereas 
tuples have the same type if and only if they have the same number of 
members, and all members have the same types. E.g:

     VALUE        TYPE
     (1, 2)         int * int
     (1, 2, 4)        int * int * int
     (57, false)            int * bool
     ('x', "buzz")       char * string

There is no such thing as a tuple with an arbitrary number of members, 
thus no function that can operate on one.

I hope that clarifies things a bit. By the way, this sort of question is 
probably best asked on the beginner's list (you'll see the address at 
the bottom of this message).

-- 
Matt Gushee
Englewood, CO, USA


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

* Re: [Caml-list] Snd question
  2005-08-15 22:41 ` [Caml-list] " Matt Gushee
@ 2005-08-16  8:08   ` sejourne kevin
  2005-08-16 13:17   ` skaller
  1 sibling, 0 replies; 19+ messages in thread
From: sejourne kevin @ 2005-08-16  8:08 UTC (permalink / raw)
  To: Matt Gushee, caml-list


--- Matt Gushee <mgushee@havenrock.com> wrote :
> There is no such thing as a tuple with an arbitrary
> number of members, 
> thus no function that can operate on one.
This look like the description of a un-mutable array
:-)


Kévin.




	

	
		
___________________________________________________________________________ 
Appel audio GRATUIT partout dans le monde avec le nouveau Yahoo! Messenger 
Téléchargez cette version sur http://fr.messenger.yahoo.com


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

* Re: [Caml-list] Snd question
  2005-08-15 22:41 ` [Caml-list] " Matt Gushee
  2005-08-16  8:08   ` sejourne kevin
@ 2005-08-16 13:17   ` skaller
  2005-08-16 16:16     ` Julian Brown
                       ` (2 more replies)
  1 sibling, 3 replies; 19+ messages in thread
From: skaller @ 2005-08-16 13:17 UTC (permalink / raw)
  To: Matt Gushee; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1886 bytes --]

On Mon, 2005-08-15 at 16:41 -0600, Matt Gushee wrote:
> Anu Engineer wrote:
> 
>  > Please forgive me if my question is very naïve, I am very new to 
> Ocaml. I was
> 
>  > wondering why snd returns an  error when I use it with more than 2 
> elements, why
> 
>  > not return the rest of the list when I apply to something larger than 
> a pair ?
> 
> 
> Your question shows your misunderstanding: snd operates on tuples, not 
> lists. 

I think the original question really meant:

Why aren't "fst" and "snd" properly generic??

For example this simply *should* work:

	snd (1,2,3)

and even pattern matching can't handle it:

	match e with (h,t,...) -> 

also should work. Felix actually supports this ugly generic
tuple projection operator:

	(1,2.1).(1)   // generic n'th of tuple
	(1,2.1,3).(1) // n must be compile time constant

and even:

var i:int;
for_each {i=0;} {i<3} {++i;} {
  print (1,2,3).[i]; // run time indexing
  endl;
};

because a tuple of all the same type is an array,
but as yet I haven't found a way to make ... work in 
pattern matches. 

It would actually be nice to have more general support
for polyadic tuple management: for example thinking about
obtaining a slice of a tuple, or concatenating two tuples,
suggests that just getting the n'th component is special case.

This kind of thing can actually be done in a hacky way
within limits with C++ template meta-programming.

A more general mapping from a list of types (at compile time)
representing tuples should be possible: any list operation
on types is a run-time operation on values. Unfortunately
I doubt camlp4 can handle that, since it is dealing with untyped
terms. Perhaps MetaOcaml can do it?

I would love to do this in Felix .. but it requires dynamic loading.

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: Snd question
  2005-08-16 13:17   ` skaller
@ 2005-08-16 16:16     ` Julian Brown
  2005-08-16 17:18       ` [Caml-list] " Alan Falloon
  2005-08-17  6:15       ` skaller
  2005-08-16 16:34     ` [Caml-list] " Jon Harrop
  2005-08-20 14:31     ` Brian Hurt
  2 siblings, 2 replies; 19+ messages in thread
From: Julian Brown @ 2005-08-16 16:16 UTC (permalink / raw)
  To: caml-list

On 2005-08-16, skaller <skaller@users.sourceforge.net> wrote:
>
> --===============0107267212==
> Content-Type: multipart/signed; micalg=pgp-sha1;
> 	protocol="application/pgp-signature";
> 	boundary="=-5lbpy9BGwsstOd4gLrxM"
>
>
> --=-5lbpy9BGwsstOd4gLrxM
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: quoted-printable
>
> On Mon, 2005-08-15 at 16:41 -0600, Matt Gushee wrote:
>> Anu Engineer wrote:
>>=20
>>  > Please forgive me if my question is very na=C3=AFve, I am very new to=20
>> Ocaml. I was
>>=20
>>  > wondering why snd returns an  error when I use it with more than 2=20
>> elements, why
>>=20
>>  > not return the rest of the list when I apply to something larger than=20
>> a pair ?
>>=20
>>=20
>> Your question shows your misunderstanding: snd operates on tuples, not=20
>> lists.=20
>
> I think the original question really meant:
>
> Why aren't "fst" and "snd" properly generic??
>
> For example this simply *should* work:
>
> 	snd (1,2,3)

What's wrong with arrays (or lists, for that matter), if you want to do
this type of operation?

Julian


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

* Re: [Caml-list] Snd question
  2005-08-16 13:17   ` skaller
  2005-08-16 16:16     ` Julian Brown
@ 2005-08-16 16:34     ` Jon Harrop
  2005-08-16 18:16       ` Richard Jones
  2005-08-17  6:28       ` skaller
  2005-08-20 14:31     ` Brian Hurt
  2 siblings, 2 replies; 19+ messages in thread
From: Jon Harrop @ 2005-08-16 16:34 UTC (permalink / raw)
  To: caml-list

On Tuesday 16 August 2005 14:17, skaller wrote:
> 	match e with (h,t,...) ->

My understanding is that the types of those expressions cannot expressed in 
the OCaml type system. So that would require quite a fundamental change.

> because a tuple of all the same type is an array,
> but as yet I haven't found a way to make ... work in
> pattern matches.

My only ellipses-related gripe is that ML patterns are designed to be linear 
but it would be nice if they could perform all linear pattern matches. 
Currently, you cannot match [|1; ...|] in OCaml.

I believe the less-elegant solution "a when Array.length a > 1 && a.(0) = 1" 
will incur a significant performance penalty when used in the middle of a 
large set of unguarded patterns.

> It would actually be nice to have more general support
> for polyadic tuple management: for example thinking about
> obtaining a slice of a tuple, or concatenating two tuples,
> suggests that just getting the n'th component is special case.

From my limited experience of SML, it is more of a pain than a benefit.

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


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

* Re: [Caml-list] Re: Snd question
  2005-08-16 16:16     ` Julian Brown
@ 2005-08-16 17:18       ` Alan Falloon
  2005-08-17  6:15       ` skaller
  1 sibling, 0 replies; 19+ messages in thread
From: Alan Falloon @ 2005-08-16 17:18 UTC (permalink / raw)
  Cc: caml-list

Julian Brown wrote:

>On 2005-08-16, skaller <skaller@users.sourceforge.net> wrote:
>  
>
>>On Mon, 2005-08-15 at 16:41 -0600, Matt Gushee wrote:
>>    
>>
>>I think the original question really meant:
>>
>>Why aren't "fst" and "snd" properly generic??
>>
>>For example this simply *should* work:
>>
>>	snd (1,2,3)
>>    
>>
>
>What's wrong with arrays (or lists, for that matter), if you want to do
>this type of operation?
>  
>
I think he also meant that it should work with tuples that actually use 
different types in each position.
So this should work:

snd ( 1, "foo", 1.2 )



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

* Re: [Caml-list] Snd question
  2005-08-16 16:34     ` [Caml-list] " Jon Harrop
@ 2005-08-16 18:16       ` Richard Jones
  2005-08-16 21:42         ` Jon Harrop
  2005-08-17 12:19         ` Alain Frisch
  2005-08-17  6:28       ` skaller
  1 sibling, 2 replies; 19+ messages in thread
From: Richard Jones @ 2005-08-16 18:16 UTC (permalink / raw)
  To: Jon Harrop; +Cc: caml-list

On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote:
> Currently, you cannot match [|1; ...|] in OCaml.

Yes!  Or, "prefix" ^ str.

> > It would actually be nice to have more general support
> > for polyadic tuple management: for example thinking about
> > obtaining a slice of a tuple, or concatenating two tuples,
> > suggests that just getting the n'th component is special case.
> 
> From my limited experience of SML, it is more of a pain than a benefit.

It'd be pretty trivial anyway to define the SML #<number> operators
using camlp4.

Rich.

-- 
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com


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

* Re: [Caml-list] Snd question
  2005-08-16 18:16       ` Richard Jones
@ 2005-08-16 21:42         ` Jon Harrop
  2005-08-17  6:55           ` skaller
  2005-08-17 12:19         ` Alain Frisch
  1 sibling, 1 reply; 19+ messages in thread
From: Jon Harrop @ 2005-08-16 21:42 UTC (permalink / raw)
  To: caml-list

On Tuesday 16 August 2005 19:16, Richard Jones wrote:
> On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote:
> > Currently, you cannot match [|1; ...|] in OCaml.
>
> Yes!  Or, "prefix" ^ str.

Unless you have a substring type I think that'll have to be: "prefix"^_

Anyway, we've had this discussion before. :-)

> > From my limited experience of SML, it is more of a pain than a benefit.
>
> It'd be pretty trivial anyway to define the SML #<number> operators
> using camlp4.

Are you sure? I was under the impression that macros didn't know about the 
type system.

Has anyone done any ad-hoc polymorphism (if that's the right jargon, I mean 
the equivalent of "+" for both int and float in SML) for containers? I 
haven't finished it yet but I've recently been playing with a term-level 
mini-Caml interpreter that I was going to add this functionality to. So 
"fold", "map" and so on are built into the language and can be applied to the 
built-in data structures set, list and array. Also, the pattern "1::2::3::_" 
can be applied to any container type.

The main problem that I can think of is the unpredictable memory use of 
substring/subarray types when they keep their "parent" around for longer than 
expected. This makes me think that it might be a bad idea...

-- 
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists


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

* Re: [Caml-list] Re: Snd question
  2005-08-16 16:16     ` Julian Brown
  2005-08-16 17:18       ` [Caml-list] " Alan Falloon
@ 2005-08-17  6:15       ` skaller
  1 sibling, 0 replies; 19+ messages in thread
From: skaller @ 2005-08-17  6:15 UTC (permalink / raw)
  To: brown; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 414 bytes --]

On Tue, 2005-08-16 at 16:16 +0000, Julian Brown wrote:

> >
> > Why aren't "fst" and "snd" properly generic??
> >
> > For example this simply *should* work:
> >
> > 	snd (1,2,3)
> 
> What's wrong with arrays (or lists, for that matter), if you want to do
> this type of operation?

Sorry, my bad example, try:

	snd (1,"Hello", 3.0)

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [Caml-list] Snd question
  2005-08-16 16:34     ` [Caml-list] " Jon Harrop
  2005-08-16 18:16       ` Richard Jones
@ 2005-08-17  6:28       ` skaller
  1 sibling, 0 replies; 19+ messages in thread
From: skaller @ 2005-08-17  6:28 UTC (permalink / raw)
  To: Jon Harrop; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

On Tue, 2005-08-16 at 17:34 +0100, Jon Harrop wrote:
> On Tuesday 16 August 2005 14:17, skaller wrote:
> > 	match e with (h,t,...) ->
> 
> My understanding is that the types of those expressions cannot expressed in 
> the OCaml type system. So that would require quite a fundamental change.

Yes.


> From my limited experience of SML, it is more of a pain than a benefit.

Good to read Barry Jay's Functorial ML ..

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [Caml-list] Snd question
  2005-08-16 21:42         ` Jon Harrop
@ 2005-08-17  6:55           ` skaller
  2005-08-18  8:20             ` Andrej Bauer
  0 siblings, 1 reply; 19+ messages in thread
From: skaller @ 2005-08-17  6:55 UTC (permalink / raw)
  To: Jon Harrop; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

On Tue, 2005-08-16 at 22:42 +0100, Jon Harrop wrote:

> Has anyone done any ad-hoc polymorphism (if that's the right jargon, I mean 
> the equivalent of "+" for both int and float in SML) for containers? I 
> haven't finished it yet but I've recently been playing with a term-level 
> mini-Caml interpreter that I was going to add this functionality to. So 
> "fold", "map" and so on are built into the language and can be applied to the 
> built-in data structures set, list and array. 

Jay's Functorial ML describes how to do this properly: 
map, fold, etc, can be applied to any
polynomial type (a type built out of sums, products,
and induction). This is polyadic = functorially polymorphic,
not ad hoc.

The rules are things like: 

map <f,g> (a,b) = (map f a, map g b)

(where <f,g> is the parallel composition of f and g).

Basically, things like 'list', 'tree', etc,
are functors, and map is just a function which takes a
functor argument and returns a map for that functor.
That is, this 'map', 'fold' etc are polyadic: they accept a functor
and return another functor.

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [Caml-list] Snd question
  2005-08-16 18:16       ` Richard Jones
  2005-08-16 21:42         ` Jon Harrop
@ 2005-08-17 12:19         ` Alain Frisch
  2005-08-17 17:21           ` skaller
  2005-08-17 23:08           ` Martin Jambon
  1 sibling, 2 replies; 19+ messages in thread
From: Alain Frisch @ 2005-08-17 12:19 UTC (permalink / raw)
  To: caml-list

Richard Jones wrote:
> On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote:
> 
>>Currently, you cannot match [|1; ...|] in OCaml.
> 
> 
> Yes!  Or, "prefix" ^ str.

This seems like a good place to insert a shameless plug. Thank you. In 
OCamlDuce (the extension of OCaml with XML types and patterns), you can 
indeed match on string prefixes:

# type t = {{ "OCaml" | "OCamlDuce" | "Other" }};;
type t = {{t}}
# fun (x : t) -> match x with {{ [ 'O' x::PCDATA ] }} -> x;;
- : {{t}} -> {{[ 'ther' | 'Caml' | 'CamlDuce' ]}} = <fun>

You can actually match on more complex regular expressions. E.g., to 
extract all the uppercase ASCII characters:

# fun (x : t) -> match x with {{ [ (x::'A'--'Z' | _)* ] }} -> x;;
- : {{t}} -> {{[ 'OC' | 'OCD' | 'O' ]}} = <fun>

or to split a string:

# let f (x : {{String}}) : {{String}} * {{String}} =
   match x with {{ [ x::PCDATA '.' y::PCDATA ] }} -> (x,y)
              | {{_}} -> raise Not_found;;
val f : {{String}} -> {{String}} * {{String}} = <fun>



-- Alain


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

* Re: [Caml-list] Snd question
  2005-08-17 12:19         ` Alain Frisch
@ 2005-08-17 17:21           ` skaller
  2005-08-17 23:08           ` Martin Jambon
  1 sibling, 0 replies; 19+ messages in thread
From: skaller @ 2005-08-17 17:21 UTC (permalink / raw)
  To: Alain Frisch; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 724 bytes --]

On Wed, 2005-08-17 at 14:19 +0200, Alain Frisch wrote:
> Richard Jones wrote:
> > On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote:
> > 
> >>Currently, you cannot match [|1; ...|] in OCaml.
> > 
> > 
> > Yes!  Or, "prefix" ^ str.
> 
> This seems like a good place to insert a shameless plug. Thank you. In 
> OCamlDuce (the extension of OCaml with XML types and patterns), you can 
> indeed match on string prefixes:
> 
> # type t = {{ "OCaml" | "OCamlDuce" | "Other" }};;

Actually it is worth reading Alain's tree automata paper: 
the idea of regular sets of strings being types 
brings exception clarity to the presentation.


-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [Caml-list] Snd question
  2005-08-17 12:19         ` Alain Frisch
  2005-08-17 17:21           ` skaller
@ 2005-08-17 23:08           ` Martin Jambon
  1 sibling, 0 replies; 19+ messages in thread
From: Martin Jambon @ 2005-08-17 23:08 UTC (permalink / raw)
  To: Alain Frisch; +Cc: caml-list

On Wed, 17 Aug 2005, Alain Frisch wrote:

> Richard Jones wrote:
>> On Tue, Aug 16, 2005 at 05:34:38PM +0100, Jon Harrop wrote:
>> 
>>> Currently, you cannot match [|1; ...|] in OCaml.
>> 
>> 
>> Yes!  Or, "prefix" ^ str.
>
> This seems like a good place to insert a shameless plug. Thank you. In 
> OCamlDuce (the extension of OCaml with XML types and patterns), you can 
> indeed match on string prefixes:
[...]

This is also something that is relatively easy with Micmatch:

$ micmatch
         Objective Caml version 3.08.3

         Camlp4 Parsing version 3.08.3

# let / "prefix" (_* as str) / = "prefixabcd";;
val str : string = "abcd"



Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr


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

* Re: [Caml-list] Snd question
  2005-08-17  6:55           ` skaller
@ 2005-08-18  8:20             ` Andrej Bauer
  2005-08-18 17:51               ` skaller
  0 siblings, 1 reply; 19+ messages in thread
From: Andrej Bauer @ 2005-08-18  8:20 UTC (permalink / raw)
  To: caml-list; +Cc: skaller

skaller wrote:
> Jay's Functorial ML describes how to do this properly: 
> map, fold, etc, can be applied to any
> polynomial type (a type built out of sums, products,
> and induction). This is polyadic = functorially polymorphic,
> not ad hoc.

Just a minor terminological remark:

A polynomial functor (functor in the sense of category theory) is
a functor built from sums, products, arrow types and type constants,
where the lhs of an arrow must be constant, e.g.

  P(x) = a * x + (b -> x) + c

Contrary to what skaller says, no inductive types are allowed in a
polynomial functor. Side remark: the fully general definition of a
polynomial functor allows an arbitrary dependend sum, not just a finite
one, so we get the general form P(x) = sum_{y : a} (b(y) -> x), where b
is a type dependent on a.

An inductive type is the initial solution to a fixed-point equation,

 t = F(t)

for some functor F. In case F is a polynomial functor, the inductive
type t is called a w-type, or a well-founded type. Such types are well
understood and have accompanying induction and recursion principles from
which various operations (map, fold, etc.) can be built systematically.

Best regards,

Andrej


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

* Re: [Caml-list] Snd question
  2005-08-18  8:20             ` Andrej Bauer
@ 2005-08-18 17:51               ` skaller
  2005-08-19  7:50                 ` Andrej Bauer
  0 siblings, 1 reply; 19+ messages in thread
From: skaller @ 2005-08-18 17:51 UTC (permalink / raw)
  To: Andrej Bauer; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 851 bytes --]

On Thu, 2005-08-18 at 10:20 +0200, Andrej Bauer wrote:
> Contrary to what skaller says, no inductive types are allowed in a
> polynomial functor. 

This isn't contrary to what I said: I didn't say inductive types
were allowed, I said the polynomial could be built *using*
induction. 

EG: 1 is a list, if L is a list then T * L is a list. It follows
T is a list, T * T is a list .. etc, and so a list is given
by the polynomial

	1 + T + T * T + T * T * T + ...

I accept this may not be the most general definition.
You said later:

"Such types are well
understood and have accompanying induction and recursion principles from
which various operations (map, fold, etc.) can be built systematically."

and I wonder why no production languages actually do that...

-- 
John Skaller <skaller at users dot sourceforge dot net>


[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

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

* Re: [Caml-list] Snd question
  2005-08-18 17:51               ` skaller
@ 2005-08-19  7:50                 ` Andrej Bauer
  0 siblings, 0 replies; 19+ messages in thread
From: Andrej Bauer @ 2005-08-19  7:50 UTC (permalink / raw)
  To: skaller; +Cc: caml-list

I was hoping skaller wouldn't object to a simple terminological point.
Oh well :-)

skaller wrote:
> EG: 1 is a list, if L is a list then T * L is a list. It follows
> T is a list, T * T is a list .. etc, and so a list is given
> by the polynomial
> 
> 	1 + T + T * T + T * T * T + ...

You are confusing the interesting observation that lists can be given
both as an inductive type and a polynomial with the definition of
polynomial functors. Polynomial functors are defined without mention of
inductive types (contrary to your _definition_). Since we are discussing
a _definition_, it is irrelevant that there are inductive types which
can also be expressed as polynomial functors. If you do not believe me,
I can give you a reference.

> "Such types are well
> understood and have accompanying induction and recursion principles from
> which various operations (map, fold, etc.) can be built systematically."
> 
> and I wonder why no production languages actually do that...

I believe the coq proof assistant (http://coq.inria.fr/) knows how to do
this, and quite possibly the Isabelle theorem prover, too. One could
presumably rip out this part of coq and put it in a programming language.

Best regards,

Andrej


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

* Re: [Caml-list] Snd question
  2005-08-16 13:17   ` skaller
  2005-08-16 16:16     ` Julian Brown
  2005-08-16 16:34     ` [Caml-list] " Jon Harrop
@ 2005-08-20 14:31     ` Brian Hurt
  2 siblings, 0 replies; 19+ messages in thread
From: Brian Hurt @ 2005-08-20 14:31 UTC (permalink / raw)
  To: skaller; +Cc: Matt Gushee, caml-list



On Tue, 16 Aug 2005, skaller wrote:

> I think the original question really meant:
>
> Why aren't "fst" and "snd" properly generic??

Sorry for joining the discussion late, but I question the need for fst and 
snd in general.  Whenever I find I'm using these functons regularly, I 
find that I'm using tuples when I should be using structures.  This is 
especially the case when I'm future proofing the data structure, i.e. I 
want to be able to add fields later on without having to rewrite all the 
code.

This is one of the things I like about Ocaml- the lack of golden hammers, 
but the rich variety of tools available.  A lot of languages do seem to 
have golden hammer data structures especially- consider lists in Lisp or 
associative arrays in Perl.  The sure sign of a golden hammer data 
structure is that it's the one you pick if you're not sure what data 
structure you need.  Now, Ocaml doesn't have one.  Ocaml doesn't have any 
one single data structure which is always the right one.  Tuples, 
structures, objects, variant types, arrays, and lists all have some 
overlap, and some unique features.  There is no golden hammer, but there 
is a rich and powerful enough set of tools that I've yet to see a 
situation where the right tool for the job wasn't at hand.

Brian


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

end of thread, other threads:[~2005-08-20 14:29 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-15 22:05 Snd question Anu Engineer
2005-08-15 22:41 ` [Caml-list] " Matt Gushee
2005-08-16  8:08   ` sejourne kevin
2005-08-16 13:17   ` skaller
2005-08-16 16:16     ` Julian Brown
2005-08-16 17:18       ` [Caml-list] " Alan Falloon
2005-08-17  6:15       ` skaller
2005-08-16 16:34     ` [Caml-list] " Jon Harrop
2005-08-16 18:16       ` Richard Jones
2005-08-16 21:42         ` Jon Harrop
2005-08-17  6:55           ` skaller
2005-08-18  8:20             ` Andrej Bauer
2005-08-18 17:51               ` skaller
2005-08-19  7:50                 ` Andrej Bauer
2005-08-17 12:19         ` Alain Frisch
2005-08-17 17:21           ` skaller
2005-08-17 23:08           ` Martin Jambon
2005-08-17  6:28       ` skaller
2005-08-20 14:31     ` Brian Hurt

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