Gmail Calendar Documents Web Reader more »
Recently Visited Groups | Help | Sign in
Google Groups Home
newbie question: printed representation for lambdas
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  23 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Marco Antoniotti  
View profile  
 More options Jan 25, 4:04 pm
Newsgroups: comp.lang.haskell
From: Marco Antoniotti <marc...@gmail.com>
Date: Mon, 25 Jan 2010 13:04:32 -0800 (PST)
Local: Mon, Jan 25 2010 4:04 pm
Subject: newbie question: printed representation for lambdas
Hi

I have

<pre>
*Main> \k -> k + 42
\k -> k + 42

<interactive>:1:0:
    No instance for (Show (a -> a))
      arising from a use of `print' at <interactive>:1:0-11
    Possible fix: add an instance declaration for (Show (a -> a))
    In a stmt of a 'do' expression: print it
</pre>

This is understandable, however, is there a way to define a 'show' for
lambdas?

Thanks
--
Marco


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark T. B. Carroll  
View profile  
 More options Jan 25, 6:00 pm
Newsgroups: comp.lang.haskell
From: "Mark T. B. Carroll" <Mark.Carr...@Aetion.com>
Date: Mon, 25 Jan 2010 18:00:33 -0500
Local: Mon, Jan 25 2010 6:00 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> writes:
> This is understandable, however, is there a way to define a 'show' for
> lambdas?

Not as far as I know, I'm afraid. At least, not a show that actually
shows you what the function does, you can write useless things like,

instance Show (a -> b) where
  show _ = "Foo"

Mark


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Jan 27, 3:34 pm
Newsgroups: comp.lang.haskell
From: Marco Antoniotti <marc...@gmail.com>
Date: Wed, 27 Jan 2010 12:34:18 -0800 (PST)
Local: Wed, Jan 27 2010 3:34 pm
Subject: Re: newbie question: printed representation for lambdas
On Jan 25, 6:00 pm, "Mark T. B. Carroll" <Mark.Carr...@Aetion.com>
wrote:

> Marco Antoniotti <marc...@gmail.com> writes:
> > This is understandable, however, is there a way to define a 'show' for
> > lambdas?

> Not as far as I know, I'm afraid. At least, not a show that actually
> shows you what the function does, you can write useless things like,

> instance Show (a -> b) where
>   show _ = "Foo"

I had done that.  Not very useful.  Plus, since :type will tell you
the type of a function (at least in ghci), I surmise the plumbing is
there to give you some info.

Cheers
--
Marco


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ertugrul Söylemez  
View profile  
 More options Jan 28, 1:25 am
Newsgroups: comp.lang.haskell
From: Ertugrul Söylemez <e...@ertes.de>
Date: Thu, 28 Jan 2010 07:25:59 +0100
Local: Thurs, Jan 28 2010 1:25 am
Subject: Re: newbie question: printed representation for lambdas

It's impossible.  To write a 'show' function for functions, you need a
tellMeWhatThisFunctionDoes function, which you obviously don't have.

Greets
Ertugrul

--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Rubin  
View profile  
 More options Jan 28, 1:48 am
Newsgroups: comp.lang.haskell
From: Paul Rubin <no.em...@nospam.invalid>
Date: Wed, 27 Jan 2010 22:48:00 -0800
Subject: Re: newbie question: printed representation for lambdas

Ertugrul Söylemez <e...@ertes.de> writes:
>> I had done that.  Not very useful.  Plus, since :type will tell you
>> the type of a function (at least in ghci), I surmise the plumbing is
>> there to give you some info.

> It's impossible.  To write a 'show' function for functions, you need a
> tellMeWhatThisFunctionDoes function, which you obviously don't have.

You can tell something about the type through Data.Typeable, though that
doesn't tell you what the function -does-.

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ertugrul Söylemez  
View profile  
 More options Jan 28, 2:44 am
Newsgroups: comp.lang.haskell
From: Ertugrul Söylemez <e...@ertes.de>
Date: Thu, 28 Jan 2010 08:44:34 +0100
Local: Thurs, Jan 28 2010 2:44 am
Subject: Re: newbie question: printed representation for lambdas

Paul Rubin <no.em...@nospam.invalid> wrote:
> Ertugrul Söylemez <e...@ertes.de> writes:
> >> I had done that.  Not very useful.  Plus, since :type will tell you
> >> the type of a function (at least in ghci), I surmise the plumbing
> >> is there to give you some info.

> > It's impossible.  To write a 'show' function for functions, you need
> > a tellMeWhatThisFunctionDoes function, which you obviously don't
> > have.

> You can tell something about the type through Data.Typeable, though
> that doesn't tell you what the function -does-.

I think that's pretty useless.  The types are static, so you wouldn't
expect 'show' to return anything that you couldn't tell right from the
source code.  If it does, then there is something seriously wrong.

Greets
Ertugrul

--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Thierbach  
View profile  
 More options Jan 27, 4:58 pm
Newsgroups: comp.lang.haskell
From: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Date: Wed, 27 Jan 2010 22:58:19 +0100
Local: Wed, Jan 27 2010 4:58 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
> On Jan 25, 6:00 pm, "Mark T. B. Carroll" <Mark.Carr...@Aetion.com>
> wrote:
>> Marco Antoniotti <marc...@gmail.com> writes:
>> > This is understandable, however, is there a way to define a 'show' for
>> > lambdas?
>> Not as far as I know, I'm afraid. At least, not a show that actually
>> shows you what the function does, you can write useless things like,
>> instance Show (a -> b) where
>>   show _ = "Foo"
> I had done that.  Not very useful.  Plus, since :type will tell you
> the type of a function (at least in ghci), I surmise the plumbing is
> there to give you some info.

That's just ghci storing the type of the function. Haskell is not Lisp,
the source code of the function isn't kept anywhere. Functions will
be compiled, specialized, inlined, optimized or otherwise modified;
and there's no way you can back the source code from that. If you try
hard enough, you might be able to access the compiled machine code,
but that won't help, will it? :-)

- Dirk


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Jan 29, 6:02 am
Newsgroups: comp.lang.haskell
From: Marco Antoniotti <marc...@gmail.com>
Date: Fri, 29 Jan 2010 03:02:29 -0800 (PST)
Local: Fri, Jan 29 2010 6:02 am
Subject: Re: newbie question: printed representation for lambdas
On Jan 27, 10:58 pm, Dirk Thierbach <dthierb...@usenet.arcornews.de>
wrote:

I do not expect the source of the function to be available.  I just
want to know that there is a function without getting an error.  The
type of the function is more than sufficient.  Besides even in
(Common) Lisp you do not necessarily have the function code available,
yet functions do have a printed representation - i.e., they get the
'Show' treatment, but they cannot be read - which, AFAIU, is what the
'Read' class is for.

prompt> (lambda (x) x)
#<some printed representation of a function #x42>

This, IMHO opinion would be very useful.

Cheers
--
Marco


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Jan 29, 6:06 am
Newsgroups: comp.lang.haskell
From: Marco Antoniotti <marc...@gmail.com>
Date: Fri, 29 Jan 2010 03:06:51 -0800 (PST)
Local: Fri, Jan 29 2010 6:06 am
Subject: Re: newbie question: printed representation for lambdas
On Jan 28, 7:25 am, Ertugrul Söylemez <e...@ertes.de> wrote:

No you don't.  I don't care what a function does.  I just don't want
an error.  You are assuming that there is only one printed
representation of a function.  It is not so.  There is a range of
possibilities, more or less informative.  An error is just one
behavior at one extreme.

Cheers
--
Marco


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Thierbach  
View profile  
 More options Jan 29, 9:05 am
Newsgroups: comp.lang.haskell
From: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Date: Fri, 29 Jan 2010 15:05:52 +0100
Local: Fri, Jan 29 2010 9:05 am
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
> I do not expect the source of the function to be available.  I just
> want to know that there is a function without getting an error.

I'm sorry, I don't understand this sentence. What exactly do you want
to do? Do you actually want to print a representation of the
function, or do you just need to check if some value is has a function
type or not, or ... ?

If you're using GHCI and want to get information about an identifier,
just use :info or :type.

> The type of the function is more than sufficient.  Besides even in
> (Common) Lisp you do not necessarily have the function code
> available, yet functions do have a printed representation

And that's different in Haskell -- no kind of printable representation
is stored together with a function at runtime. Unless you make
up your own datatype and store it yourself (which might be possible
with a bit of typeclass hackery, but very awkward).

GHCI does store additional information, but this information is not
available in a compiled executable, so you cannot rely on its
availability inside the language itself (e.g., using Show).

> prompt> (lambda (x) x)
> #<some printed representation of a function #x42>
> This, IMHO opinion would be very useful.

Why would it be useful? Haskell is a *compiled* language in the first
place. Yes, Lisp has a different philosophy, but Haskell is not Lisp.

In Haskell, one cannot compare functions for equality, one cannot
inspect them, one cannot change them. And that's done on purpose.

If you want to see the source code, just go look it up in the file.
Customize Emacs/your IDE if you do it often. Or use :list. GHCI is
fine for testing stuff and experiments, but don't use it as your main
developing environment. You need some kind of editor.

- Dirk


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark T. B. Carroll  
View profile  
 More options Jan 29, 10:40 am
Newsgroups: comp.lang.haskell
From: "Mark T. B. Carroll" <Mark.Carr...@Aetion.com>
Date: Fri, 29 Jan 2010 10:40:54 -0500
Local: Fri, Jan 29 2010 10:40 am
Subject: Re: newbie question: printed representation for lambdas

Dirk Thierbach <dthierb...@usenet.arcornews.de> writes:
> If you want to see the source code, just go look it up in the file.
> Customize Emacs/your IDE if you do it often.

Furthermore, http://hackage.haskell.org/package/hasktags will make tag
index files that many editors can use to make the lookup very easy.

Mark


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Jan 29, 10:49 am
Newsgroups: comp.lang.haskell
From: Marco Antoniotti <marc...@gmail.com>
Date: Fri, 29 Jan 2010 07:49:50 -0800 (PST)
Local: Fri, Jan 29 2010 10:49 am
Subject: Re: newbie question: printed representation for lambdas
On Jan 29, 3:05 pm, Dirk Thierbach <dthierb...@usenet.arcornews.de>
wrote:

This begs the question.  Why is this useless?

> Haskell is a *compiled* language in the first
> place. Yes, Lisp has a different philosophy, but Haskell is not Lisp.

There is no different philosophy here.  (Common) Lisp is a compiled
language as well where the following does *not* generate an error

(defmethod pf ((f function)) (print f))

(pf (lambda (x) (+ x 42)))

If the above is in a file and I execute it (for an appropriate
definition of "execute") I will not get an error.  In Haskell I do and
it is just annoying.

> In Haskell, one cannot compare functions for equality, one cannot
> inspect them, one cannot change them. And that's done on purpose.

> If you want to see the source code, just go look it up in the file.
> Customize Emacs/your IDE if you do it often. Or use :list. GHCI is
> fine for testing stuff and experiments, but don't use it as your main
> developing environment. You need some kind of editor.

I am a very fine Emacs hacker, thank you.  I just did a very normal
thing with it: I produced a cup of coffe. :)  I know I could - in
principle - construct a coffee maker with Emacs; it's just a SMOP. :)

I am sorry but I disagree with your take on the issue and I don't buy
your arguments.

If Haskell is a compiled language, why have ghci at all?  Once you
have an interpreter of sorts, the issue of printed representation of
anyhting does arise.  And, given that - rightly so - functions are
first class objects in Haskell, how do you "debug" a program?  At a
certain point, in some place you will have a function and your
debugger (which I have not tried - I will grant you that) will have to
show you what is in that place; hence the issue of a printed
representation of a function object does arise.  Moreover, why does
ghci prints 42 instead of XLII?

But, in any case, you are not making a convincing case that I should
not be able to just have

  foo x = do print (\k -> k + x + 1)
  main = foo 42

in a file, compile it and run it, just to have "something" printed
out.

Again, I do not care about comparing functions, nor inspecting their
code at runtime.  But this is not what I ask.  I ask that ghci did
something sensible, and - in general - that a derivation of Show
existed for arrow types.  I don't care about the format; I do not need
to use it in code.  But the error signaling is just plain annoying.

Having said that, I understand that this is simply not doable in the
language/implementation... as is.  Unless there were some deep typing
issues (of which I confess my ignorance) I just don't see why there
should not be a 'show' for function objects, at least in ghci.

Cheers
--
Marco


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dan Doel  
View profile  
 More options Jan 29, 12:46 pm
Newsgroups: comp.lang.haskell
Followup-To: comp.lang.haskell
From: Dan Doel <dan.d...@gmail.com>
Date: Fri, 29 Jan 2010 12:46:23 -0500
Local: Fri, Jan 29 2010 12:46 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti wrote:
> This begs the question.  Why is this useless?

Because being able to write "print foo" where foo is a function, and have
"something" appear on the screen simply is useless. It's much clearer to
write:

  print "something"

instead, if you want "something" to appear on the screen.

The only printing you could do of functions that would give you any useful
information about the function is for a somehow enumerable domain, and
showable codomain, in which case you could write something like:

  instance (Enumerable a, Show a, Show b) => Show (a -> b) where
    show f = concatMap (\x -> show x ++ " |-> " ++ show f x ++ "\n")
                enumerate

Which for, say, not, will give you:

  False |-> True
  True |-> False

This is the only sort of showing that can be permitted, however, because any
representation produced based on the code, or pointers underlying the
implementation would violate either referential transparency or
extensionality, both of which are desirable formal properties for the
language to adhere to.

(And incidentally, the above Show instance violates the purpose of the Show
class, which is to produce valid Haskell code for the given value, such that
you could paste the string you get from 'show' into a source file, and get
back the same value you passed to 'show'. This isn't possible for functions
without compiler/interpreter magic, and as I mentioned above, it's ill-
advised compiler magic.)

Your complaint seems to center around wanting to type functions into GHCi
without getting errors that they aren't showable. But why do you want to do
that? Why is GHCi spitting out:

  This is a function.

on a line better than spitting out an error message?


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Thierbach  
View profile  
 More options Jan 29, 2:17 pm
Newsgroups: comp.lang.haskell
From: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Date: Fri, 29 Jan 2010 20:17:40 +0100
Local: Fri, Jan 29 2010 2:17 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
> On Jan 29, 3:05 pm, Dirk Thierbach <dthierb...@usenet.arcornews.de>
> wrote:
>> Marco Antoniotti <marc...@gmail.com> wrote:
>>> prompt> (lambda (x) x)
>>> #<some printed representation of a function #x42>
>>> This, IMHO opinion would be very useful.
>> Why would it be useful?
> This begs the question.  Why is this useless?

I can't think of an actual application where I'd want to use it. Maybe
you can tell me one?

[...]

> If the above is in a file and I execute it (for an appropriate
> definition of "execute") I will not get an error.  In Haskell I do and
> it is just annoying.

Why is it annoying? What do you want to use it for?

> If Haskell is a compiled language, why have ghci at all?

For experimentation, and testing.

> Once you have an interpreter of sorts, the issue of printed
> representation of anyhting does arise.

Yes. That's why GHCI stores the location of the source code internally,
so it can print it. But that's a feature of *GHCI*, not of *Haskell*.
Typeclasses, and especially the Show class, are part of the Haskell
language.

The compiler and/or interpreter are not Haskell. There is no
metacircularity.

> And, given that - rightly so - functions are
> first class objects in Haskell, how do you "debug" a program?

By using the Debugger, or QuickCheck, or by testing functions bottom
up in GHCI.

> At a certain point, in some place you will have a function and your
> debugger (which I have not tried - I will grant you that) will have
> to show you what is in that place;

The debugger can show you at which place in the source code you are,
and list the source code. It can also show an internal representation
of an expression. GHCI can also use the :print operation:

Prelude> let f x = x + 1
Prelude> :print f
f = (_t1::a -> a)

Again note, that is a feature of GHCI, and has nothing to do with
the Haskell language itself, and especially not the typeclass Show.
You can't do something like this in a standalone executable.

> But, in any case, you are not making a convincing case that I should
> not be able to just have

>  foo x = do print (\k -> k + x + 1)
>  main = foo 42

> in a file, compile it and run it, just to have "something" printed
> out.

You are able to do that: Just add an instance declaration for Show
that prints "something" for every function. But how is that useful?

Haskell is *restrictive*. An attitude like "hey, I want it this way,
and I don't want to do it in another way, even if it's easily possible
in that other way" won't get you very far. If you fight the language,
instead of trying to understand how things are and why they are this
way, you won't have a lot of fun with Haskell. Your choice, of course.

> But the error signaling is just plain annoying.

Ok. So your complaint is that you just typed an identifier, got an
error, and are now upset about that. And instead of using :info,
:print or whatever, you want to change everything the way you would
like it to have? Because that's the way you could do it in Lisp, and
you're unhappy if you cannot do it in exactly the same way? Did I
understand that correctly?

- Dirk


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ertugrul Söylemez  
View profile  
 More options Jan 30, 12:24 am
Newsgroups: comp.lang.haskell
From: Ertugrul Söylemez <e...@ertes.de>
Date: Sat, 30 Jan 2010 06:24:15 +0100
Local: Sat, Jan 30 2010 12:24 am
Subject: Re: newbie question: printed representation for lambdas

You cannot extract anything from a function other than its type.
Remember that the lexical rules of other languages don't hold in
Haskell.  Most functions in Haskell are not written down explicitly, but
rather computed on the fly.  We use combinators heavily.  Writing a Show
instance would require carrying all this information along at run time!
That's not just very memory-hungry, it could even change the semantics
of the language, not to mention that you would need to be able to
extract that information in some pure way.

Greets
Ertugrul

--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ertugrul Söylemez  
View profile  
 More options Jan 30, 12:31 am
Newsgroups: comp.lang.haskell
From: Ertugrul Söylemez <e...@ertes.de>
Date: Sat, 30 Jan 2010 06:31:25 +0100
Local: Sat, Jan 30 2010 12:31 am
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
> I do not expect the source of the function to be available.  I just
> want to know that there is a function without getting an error.  The
> type of the function is more than sufficient.  Besides even in
> (Common) Lisp you do not necessarily have the function code available,
> yet functions do have a printed representation - i.e., they get the
> 'Show' treatment, but they cannot be read - which, AFAIU, is what the
> 'Read' class is for.

> prompt> (lambda (x) x)
> #<some printed representation of a function #x42>

> This, IMHO opinion would be very useful.

Haskell is not Lisp, as has been noted a number of times.  You could
print "this is a function", which is quite useless.  You could also
print its type, but then you would already restrict the space of
showable functions to a very small subset of all functions.

What's the point of this anyway?  In Haskell you get the error message
that there is no Show instance for whatever type your function might
have.  This is much more informative than printing something useless.

Really, what's the point of printing this stuff?

Greets
Ertugrul

--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nobody  
View profile  
 More options Jan 30, 10:11 am
Newsgroups: comp.lang.haskell
From: Nobody <nob...@nowhere.com>
Date: Sat, 30 Jan 2010 15:11:22 +0000
Local: Sat, Jan 30 2010 10:11 am
Subject: Re: newbie question: printed representation for lambdas

On Fri, 29 Jan 2010 07:49:50 -0800, Marco Antoniotti wrote:
> But, in any case, you are not making a convincing case that I should
> not be able to just have

>   foo x = do print (\k -> k + x + 1)
>   main = foo 42

> in a file, compile it and run it, just to have "something" printed
> out.

Fine:

        instance Show (a -> b) where
          show _ = "something"


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Antoniotti  
View profile  
 More options Jan 30, 3:12 pm
Newsgroups: comp.lang.haskell
From: Marco Antoniotti <marc...@gmail.com>
Date: Sat, 30 Jan 2010 12:12:46 -0800 (PST)
Local: Sat, Jan 30 2010 3:12 pm
Subject: Re: newbie question: printed representation for lambdas
On Jan 30, 4:11 pm, Nobody <nob...@nowhere.com> wrote:

> On Fri, 29 Jan 2010 07:49:50 -0800, Marco Antoniotti wrote:
> > But, in any case, you are not making a convincing case that I should
> > not be able to just have

> >   foo x = do print (\k -> k + x + 1)
> >   main = foo 42

> > in a file, compile it and run it, just to have "something" printed
> > out.

> Fine:

>         instance Show (a -> b) where
>           show _ = "something"

Look guys!  I don't want to troll.  I tried that and it is relatively
useless.  The :print command is better.  I just don't buy your
arguments (as I don't see how it would break the type system) and I do
not have the time to hack around.  Printing the type and and "id" of a
function (after all they all do get created at some time in memory)
would be useful.

As for the application, it is essentially for debugging reasons.  If
you don't see this fine.  I just think it would make life easier to
other people, like me.

Cheers
--
Marco


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Rubin  
View profile  
 More options Jan 30, 3:39 pm
Newsgroups: comp.lang.haskell
From: Paul Rubin <no.em...@nospam.invalid>
Date: Sat, 30 Jan 2010 12:39:28 -0800
Local: Sat, Jan 30 2010 3:39 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> writes:
> Printing the type and and "id" of a
> function (after all they all do get created at some time in memory)
> would be useful.

Lots of times they are never created.  They are like intermediate values
in arithmetic expressions, that get optimized away by the compiler.
They can even get created more than once, so they don't have a unique
address.  For example, a polymorphic function can be specialized into
several monomorphic functions of differing types.  Printing the type
info at runtime is also problematic for the same reason: do you want the
polymorphic type, or the type at a particular instantiation?  The latter
is generally not available after compilation.

It occurs to me though, there is an alternative that I think would be a
lot more useful: a way to ask ghci for the type of a term beginning at a
given offset in the source file, so you could get the type of some
expression locally bound in a "let" or "where" clause that's not
accessible to :t at the top level.  The idea is you'd connect that
feature to an Emacs command or some IDE feature and then you could find
the type of any term by selecting it with the mouse and entering a
command or clicking something.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Thierbach  
View profile  
 More options Jan 30, 4:07 pm
Newsgroups: comp.lang.haskell
From: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Date: Sat, 30 Jan 2010 22:07:23 +0100
Local: Sat, Jan 30 2010 4:07 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
>>         instance Show (a -> b) where
>>           show _ = "something"
> Look guys!  I don't want to troll.  I tried that and it is relatively
> useless.  

So we told you.

> The :print command is better.  I just don't buy your
> arguments (as I don't see how it would break the type system)

It doesn't break the type system. It does break extensionality:
In Haskell, expressions don't have an "identity". As I already told
you, functions can be moved around, optimized, inlined, and what not.
Having an "identity" would be meaningless.

> and I do not have the time to hack around.  

Then don't :-)

> Printing the type and and "id" of a function (after all they all do
> get created at some time in memory)

Let me repeat: The function may exist as multiple copies, optimized
for certain types, partially evaluated, etc. It does not have an
"id". In GHCI, which doesn't do a lot of optimization, it has a
somewhat simpler internal representation, which gets printed with
:print, and from the debugger. That's all.

At runtime, you can't even access the type of a function, because
types only exist at compile-time. What you can do is to use the types
at compile-time to insert additional information, with help of
typeclasses. Have a look at Data.Typeable for that. That's very
different from the :type command, which accesses additional information
that's stored in GHCI (and as such, not part of Haskell).

> As for the application, it is essentially for debugging reasons.

Let me repeat: And for debugging reasons, it works fine from GHCI. It
just doesn't work in the language itself. Because debugging isn't
something you do *in* the language, it's something you do *with* the
language. Unlike Lisp, which lumps those two things together.

> If you don't see this fine.

Since you can do it for debugging, I still don't see any reason to want
to do it in the language itself.

> I just think it would make life easier to other people, like me.

I'm still missing a concrete application where it really would make
life easier. Let me repeat: Debugging isn't done *in* Haskell. So
having a "Show" instance is completely independent if that application.

- Dirk


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dirk Thierbach  
View profile  
 More options Jan 30, 5:26 pm
Newsgroups: comp.lang.haskell
From: Dirk Thierbach <dthierb...@usenet.arcornews.de>
Date: Sat, 30 Jan 2010 23:26:30 +0100
Local: Sat, Jan 30 2010 5:26 pm
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
>>         instance Show (a -> b) where
>>           show _ = "something"
> Look guys!  I don't want to troll.  I tried that and it is relatively
> useless.  

So we told you.

> The :print command is better.  I just don't buy your
> arguments (as I don't see how it would break the type system)

It doesn't break the type system. It does break extensionality:
In Haskell, expressions don't have an "identity". As I already told
you, functions can be moved around, optimized, inlined, and what not.
Having an "identity" would be meaningless.

> and I do not have the time to hack around.  

Then don't :-)

> Printing the type and and "id" of a function (after all they all do
> get created at some time in memory)

Let me repeat: The function may exist as multiple copies, optimized
for certain types, partially evaluated, etc. It does not have an
"id". In GHCI, which doesn't do a lot of optimization, it has a
somewhat simpler internal representation, which gets printed with
:print, and from the debugger. That's all.

At runtime, you can't even access the type of a function, because
types only exist at compile-time. What you can do is to use the types
at compile-time to insert additional information, with help of
typeclasses. Have a look at Data.Typeable for that. That's very
different from the :type command, which accesses additional information
that's stored in GHCI (and as such, not part of Haskell).

> As for the application, it is essentially for debugging reasons.

Let me repeat: And for debugging reasons, it works fine from GHCI. It
just doesn't work in the language itself. Because debugging isn't
something you do *in* the language, it's something you do *with* the
language. Unlike Lisp, which lumps those two things together.

> If you don't see this fine.

Since you can do it for debugging, I still don't see any reason to want
to do it in the language itself.

> I just think it would make life easier to other people, like me.

I'm still missing a concrete application where it really would make
life easier. Let me repeat: Debugging isn't done *in* Haskell. So
having a "Show" instance is completely independent of that application.

- Dirk


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ertugrul Söylemez  
View profile  
 More options Jan 31, 6:23 am
Newsgroups: comp.lang.haskell
From: Ertugrul Söylemez <e...@ertes.de>
Date: Sun, 31 Jan 2010 12:23:22 +0100
Local: Sun, Jan 31 2010 6:23 am
Subject: Re: newbie question: printed representation for lambdas

Marco Antoniotti <marc...@gmail.com> wrote:
> > Fine:

> >         instance Show (a -> b) where
> >           show _ = "something"

> Look guys!  I don't want to troll.  I tried that and it is relatively
> useless.  The :print command is better.  I just don't buy your
> arguments (as I don't see how it would break the type system) and I do
> not have the time to hack around.  Printing the type and and "id" of a
> function (after all they all do get created at some time in memory)
> would be useful.

Note that the address of a function may have changed between two calls
of 'show', so you would need something like this:

  showIO :: a -> IO String

Next problem:  Semantically this showIO function doesn't make sense.  It
would be wrong to return anything useful about its argument.  To see why
this is a problem, try to implement a function of type a -> String.
This function cannot return anything meaningful.  In fact, this function
is either constant or undefined.

With access to the IO world, the showIO function doesn't have to be
constant, but it still cannot return anything useful about its argument.
Semantically it does not make sense.

> As for the application, it is essentially for debugging reasons.  If
> you don't see this fine.  I just think it would make life easier to
> other people, like me.

I think, you are thinking in other languages.  In Haskell that
information is completely useless.  You will not know anything more
about the function than that it is a function.  However, you know that
already, because you have its type.  If it contains a (->) anywhere,
then it's a function.

As others have noted, the big type and function work of Haskell is done
at compile time.  That information is lost or scattered around the
entire executable file afterwards.  Functions get optimized away
entirely and may get moved around in memory.

Use the debugging capabilities of your interpreter.  You don't do the
debugging of your programs in your programs themselves.

Greets
Ertugrul

--
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://blog.ertes.de/


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nobody  
View profile  
 More options Jan 31, 2:52 pm
Newsgroups: comp.lang.haskell
From: Nobody <nob...@nowhere.com>
Date: Sun, 31 Jan 2010 19:52:25 +0000
Local: Sun, Jan 31 2010 2:52 pm
Subject: Re: newbie question: printed representation for lambdas

On Sat, 30 Jan 2010 12:12:46 -0800, Marco Antoniotti wrote:
>> > But, in any case, you are not making a convincing case that I should
>> > not be able to just have

>> >   foo x = do print (\k -> k + x + 1)   main = foo 42

>> > in a file, compile it and run it, just to have "something" printed
>> > out.

>> Fine:

>>         instance Show (a -> b) where
>              show _ = "something"

> Look guys!  I don't want to troll.

Well don't, then.

You asked a question, you got an answer. Don't like the answer? Tough,
because it's the correct answer, and any other answer isn't correct.
It's not as if you'll eventually get a different answer if you keep
asking.

> I tried that and it is relatively
> useless.  The :print command is better.  I just don't buy your arguments
> (as I don't see how it would break the type system)

Not understanding why something is true doesn't make it less true.
Particularly if the main reason behind the lack of understanding is a
refusal to hear anything which you don't want to hear.

> and I do not have the
> time to hack around.  Printing the type and and "id" of a function

A function doesn't have an "id". And printing its type is only possible if
you can print both its argument and return types; if you can, you can use
e.g.:

        import Data.Typeable

        instance (Typeable a, Typeable b) => Show (a -> b) where
            show f = "#<function: " ++ show (typeOf f) ++ ">"

But this won't necessarily do what you expect, as any value occurring at
run-time must have a concrete type (i.e. you can't have a value of type
"a -> b"; both type variables must be instantiated). If you try using the
above in ghci, you'll get:

        *Main> \x -> x * x
        #<function: Integer -> Integer>

due to the default typing rules. OTOH, if you use it in a program, e.g.:

        f x = x * x

        main = do
            print f

you'll get a complaint about an ambiguous type variable.

> (after all they all do get created at some time in memory)

In general: no they don't. And not just functions; "values" are
expressions which get reduced to WHNF as and when needed. If a value gets
used multiple times, it may actually be re-created each time (this is an
implementation detail; as there's no concept of "identity" in the
language, it isn't visible).

> As for the application, it is essentially for debugging reasons.  If you
> don't see this fine.  I just think it would make life easier to other
> people, like me.

Whether or not it would be convenient for something to be true bears no
relation to whether or not it's actually true.

You may as well ask for a C function which returns the type of the object
to which a "void *" points. It doesn't matter how useful such a function
would be, the nature of C is such that it cannot be implemented.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google