Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  Unwrap an expression? (Christopher Howard)
   2. Re:  Unwrap an expression? (Brent Yorgey)


----------------------------------------------------------------------

Message: 1
Date: Fri, 02 Sep 2011 14:23:40 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] Unwrap an expression?
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Perhaps this is a dumb question, but I was pondering the whole "Lazy" 
aspect of Haskell, and was curious: is there someway you could create a 
function "M", which you could pass an expression into, so that...

M (f (g... (n (x)) ...)) returns f

and/or returns the inner value (g... (n (x)) ...)

I don't know if that breaks the whole "referential transparency" idea or 
not, but with all those lambda calculus tricks I've heard about, and the 
lazy evaluation, I thought it would be worth asking.

-- 
frigidcode.com
theologia.indicium.us



------------------------------

Message: 2
Date: Fri, 2 Sep 2011 20:19:04 -0400
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] Unwrap an expression?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Fri, Sep 02, 2011 at 02:23:40PM -0800, Christopher Howard wrote:
> Perhaps this is a dumb question, but I was pondering the whole "Lazy"
> aspect of Haskell, and was curious: is there someway you could create
> a function "M", which you could pass an expression into, so that...
> 
> M (f (g... (n (x)) ...)) returns f
> 
> and/or returns the inner value (g... (n (x)) ...)
> 
> I don't know if that breaks the whole "referential transparency" idea
> or not, but with all those lambda calculus tricks I've heard about,
> and the lazy evaluation, I thought it would be worth asking.

It's a good question.  You cannot do this, and you're right that it
breaks referential transparency.  For example, suppose we have

  f x = x + 3

Now using our mythical M function, we should be able to do

  M (f 6)

and get f (or 6) as the result.  But f 6 = 9 so we should be able to
replace it, like so:

  M 9

but what is M 9? An error? In general, anything that works by
inspecting the *syntax* of expressions will break referential
transparency.

Even more simply, however, you might also want to consider: what would
the type of M be?

-Brent



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 39, Issue 3
****************************************

Reply via email to