- Contemporary messages sorted: [ by date ] [ by thread ] [ by subject ] [ by author ] [ by messages with attachments ]

From: Philip Wadler <wadler_at_research.bell-labs.com>

Date: Thu, 03 Jul 1997 12:52:04 -0400

I don't find either Sergio's and Harold's examples very convincing,

as both are easy to program in Haskell. I'm sure there are examples

of programs that are easy to write in Curry but not so easy to write in

Haskell, let's see some please! Cheers, -- P

1. Sergio's example:

permute [] = []

permute (x:xs) | u++v == permute xs = u++[x]++v

The same in Haskell (returns a list of all possible permutations):

permute [] = [[]]

permute (x:xs) = [ take i ys ++ [x] ++ drop i ys

| ys <- permute xs, i <- [0..length ys] ]

This is slightly longer, but makes explicit the order in which the

permutations are examined. The functions (++), take, drop, and length

are part of the standard library.

2. Harold's example:

pairlists([],[]) = []

pairlists([X|L],[Y|M]) = [[X,Y]|pairlists(L,M)]

numbered([],N).

numbered([[X,N]|R],N) :- numbered(R,+(N,1)).

before([X1,Y1],[X2,Y2]) :- string<(X1,X2).

serialise(L) = R if numbered(qsort[before](pairlists(L,R)),1)

The same in Haskell:

before (x1,y1) (x2,y2) = x1 <= x2

serialise l = map fst (sortBy before (zip (l, [1..])))

The functions (<=), map, fst, sortBy, and zip are part of the standard

library.

The library functions can be found in:

http://haskell.systemsz.cs.yale.edu/onlinereport/standard-prelude.html

http://haskell.systemsz.cs.yale.edu/onlinelibrary/list.html

And here's the Haskell home page:

http://www.haskell.org/

Received on Thu Jul 03 1997 - 19:54:00 CEST

Date: Thu, 03 Jul 1997 12:52:04 -0400

I don't find either Sergio's and Harold's examples very convincing,

as both are easy to program in Haskell. I'm sure there are examples

of programs that are easy to write in Curry but not so easy to write in

Haskell, let's see some please! Cheers, -- P

1. Sergio's example:

permute [] = []

permute (x:xs) | u++v == permute xs = u++[x]++v

The same in Haskell (returns a list of all possible permutations):

permute [] = [[]]

permute (x:xs) = [ take i ys ++ [x] ++ drop i ys

| ys <- permute xs, i <- [0..length ys] ]

This is slightly longer, but makes explicit the order in which the

permutations are examined. The functions (++), take, drop, and length

are part of the standard library.

2. Harold's example:

pairlists([],[]) = []

pairlists([X|L],[Y|M]) = [[X,Y]|pairlists(L,M)]

numbered([],N).

numbered([[X,N]|R],N) :- numbered(R,+(N,1)).

before([X1,Y1],[X2,Y2]) :- string<(X1,X2).

serialise(L) = R if numbered(qsort[before](pairlists(L,R)),1)

The same in Haskell:

before (x1,y1) (x2,y2) = x1 <= x2

serialise l = map fst (sortBy before (zip (l, [1..])))

The functions (<=), map, fst, sortBy, and zip are part of the standard

library.

The library functions can be found in:

http://haskell.systemsz.cs.yale.edu/onlinereport/standard-prelude.html

http://haskell.systemsz.cs.yale.edu/onlinelibrary/list.html

And here's the Haskell home page:

http://www.haskell.org/

Received on Thu Jul 03 1997 - 19:54:00 CEST

*
This archive was generated by hypermail 2.3.0
: Mon Nov 11 2019 - 07:15:05 CET
*