[Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-05 Thread Ben Franksen
Achim Schneider wrote:
 ...is a paper about automatic specialisation of functions by unboxing
 arguments, one could say. I'm only on page 6, but already survived the
 first formalisms, which is bound to mean that the rest of the paper is
 likewise accessible, as hinted on at ltu.
 
 http://www.cs.nott.ac.uk/~gmh/wrapper.pdf
 
 The transformation itself is mindbogglingly easy, which makes this a
 good start: You only have to understand the formalisms, not so much what
 the formalisms are representing. To quote spj: It usually turns out to
 be more interesting and challenging than it seemed at first.
 
 I'm tempted to write that this is a paper for everyone trying to figure
 out what the heck Jonathan is talking about.

Hey Achim

many thanks for bringing this wonderful paper to my attention. Dijkstra's
soul breethes out of every equation...

Cheers
Ben

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-05 Thread Ben Franksen
Isaac Dupree wrote:
 Achim Schneider wrote:
 http://www.cs.nott.ac.uk/~gmh/wrapper.pdf
 
 on page 6, stronger vs weaker seemed backwards to me... isn't (wrap ◦
 unwrap = idA) a stronger condition than (wrap ◦ unwrap ◦ body = body),
 because it tells you more, and is true in fewer cases? (which is also
 why you want to assume (wrap ◦ unwrap = idA) when you can, because it's
 the most useful one for subsequent program transformation)

Ah, thanks you say that, I have been asking myself if that was just me,
having things backward. In my book, stronger = weaker, too.

Cheers
Ben

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Achim Schneider
Achim Schneider [EMAIL PROTECTED] wrote:

 [...]

I'm trying to grok that

[] = id
++ = .

in the context of Hughes lists.

I guess it would stop to slip away if I knew what : corresponds to.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Brent Yorgey
On Jan 3, 2008 6:08 AM, Achim Schneider [EMAIL PROTECTED] wrote:

 Achim Schneider [EMAIL PROTECTED] wrote:

  [...]

 I'm trying to grok that

 [] = id
 ++ = .

 in the context of Hughes lists.

 I guess it would stop to slip away if I knew what : corresponds to.


Well, (:) has type a - [a] - [a], so a function corresponding to (:) for
Hughes lists should have type

foo :: a - H a - H a

that is,

foo :: a - ([a] - [a]) - [a] - [a]

so it can be written

foo x h = (x:) . h

which lambdabot informs me can also be written as (.) . (:).  But in the end
I'm not sure how helpful that is for understanding Hughes lists! I think the
key sentence from the paper is this: by representing a list xs as the
function (xs ++) that appends this list to another list that has still to be
supplied.  If you understand that sentence, then you can understand why []
is id and (++) is (.).

-Brent
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Achim Schneider
Brent Yorgey [EMAIL PROTECTED] wrote:

 
 Well, (:) has type a - [a] - [a], so a function corresponding to
 (:) for Hughes lists should have type
 
 foo :: a - H a - H a
 
 [...]
 I think the key sentence from the paper is this: by
 representing a list xs as the function (xs ++) that appends this list
 to another list that has still to be supplied.  If you understand
 that sentence, then you can understand why [] is id and (++) is (.).
 
Yes, I did.

They key was not thinking that : has type

(:) :: a - a - [a]

, or, put differently, beat the lisp out of me, thanks.

The problem is merely that Haskell and lisp are too similar in a much
too different way.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Achim Schneider
Achim Schneider [EMAIL PROTECTED] wrote:

 Brent Yorgey [EMAIL PROTECTED] wrote:
 
  
  Well, (:) has type a - [a] - [a], so a function corresponding to
  (:) for Hughes lists should have type
  
  foo :: a - H a - H a
  
  [...]
  I think the key sentence from the paper is this: by
  representing a list xs as the function (xs ++) that appends this
  list to another list that has still to be supplied.  If you
  understand that sentence, then you can understand why [] is id and
  (++) is (.).
  
 Yes, I did.
 
 They key was not thinking that : has type
 
 (:) :: a - a - [a]
 
 , or, put differently, beat the lisp out of me, thanks.
 
What the hell am I talking about?

(define (cons x y)
   (lambda (m) (m x y)))
 
(define (car z)
   (z (lambda (p q) p)))

(define (cdr z)
   (z (lambda (p q) q)))

: is, in a sense, \.

-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Isaac Dupree

Achim Schneider wrote:

Achim Schneider [EMAIL PROTECTED] wrote:


[...]


I'm trying to grok that

[] = id
++ = .

in the context of Hughes lists.


they are also known as difference lists, and also used at type String 
in the Prelude as ShowS, to help avoid quadratic behavior when making 
complicated Strings.  the [a]-[a] is not an ordinary function -- it's 
expected not to examine its argument, just to use it exactly once (is 
there a formal way to say that?)


~Isaac
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Achim Schneider
Achim Schneider [EMAIL PROTECTED] wrote:

 (define (cons x y)
(lambda (m) (m x y)))
  
 (define (car z)
(z (lambda (p q) p)))
 
 (define (cdr z)
(z (lambda (p q) q)))
 
, which, just for completeness, can be of course also be done in
Haskell:

cons :: a - b - (a - b - c) - c
cons x y m = m x y

car :: ((a - b - a) - c) - c 
car z = z $ \p q - p

cdr :: ((a - b - b) - c) - c
cdr z = z $ \p q - q

Prelude car $ cdr $ cdr $ cons 1 $ cons 2 $ cons 3 ()
3


-- 
(c) this sig last receiving data processing entity. Inspect headers for
past copyright information. All rights reserved. Unauthorised copying,
hiring, renting, public performance and/or broadcasting of this
signature prohibited. 

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: The Worker/Wrapper Transformation

2008-01-03 Thread Jonathan Cast

On 3 Jan 2008, at 4:49 AM, Isaac Dupree wrote:


Achim Schneider wrote:

Achim Schneider [EMAIL PROTECTED] wrote:

[...]

I'm trying to grok that
[] = id
++ = .
in the context of Hughes lists.


they are also known as difference lists, and also used at type  
String in the Prelude as ShowS, to help avoid quadratic behavior  
when making complicated Strings.  the [a]-[a] is not an ordinary  
function -- it's expected not to examine its argument, just to use  
it exactly once (is there a formal way to say that?)


f xn = f [] ++ xn

is the first thing off the top of my head.

OTOH, examining your argument (while, strictly speaking unsafe) is  
pretty darn cool:


f [] = foo
f (c:s) | isAlphaNum c = foo ++c:s
| otherwise= foo++c:s

Token prepend.

jcc

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe