http://en.wikipedia.org/wiki/First-class_object
The term was coined by Christopher Strachey in the context of “functions as first-class citizens” in the mid-1960's.[1] Depending on the language, this can imply: 1. being expressible as an anonymous literal value 2. being storable in variables 3. being storable in data structures 4. having an intrinsic identity (independent of any given name) 5. being comparable for equality with other entities 6. being passable as a parameter to a procedure/function 7. being returnable as the result of a procedure/function 8. being constructable at runtime 9. being printable 10. being readable 11. being transmissible among distributed processes 12. being storable outside running processes I'll guess that 5,9,12 does not apply to Haskell functions. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On 12/27/07, Cristian Baboi <[hidden email]> wrote:
> http://en.wikipedia.org/wiki/First-class_object > > The term was coined by Christopher Strachey in the context of "functions > as first-class citizens" in the mid-1960's.[1] > > Depending on the language, this can imply: > 1. being expressible as an anonymous literal value > 2. being storable in variables > 3. being storable in data structures > 4. having an intrinsic identity (independent of any given name) > 5. being comparable for equality with other entities > 6. being passable as a parameter to a procedure/function > 7. being returnable as the result of a procedure/function > 8. being constructable at runtime > 9. being printable > 10. being readable > 11. being transmissible among distributed processes > 12. being storable outside running processes > > I'll guess that 5,9,12 does not apply to Haskell functions. > I don't think this is meant as a list of requirements, but as examples of what being first class *can* mean. So yes, in Haskell some of these points don't make much sense. -- Sebastian Sylvan +44(0)7857-300802 UIN: 44640862 _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
Cristian Baboi wrote:
> http://en.wikipedia.org/wiki/First-class_object > I'll guess that 5,9,12 does not apply to Haskell functions. I think there is a basic semantic difference between what the author of that article meant by the word "function" and what we mean by that word when we are talking about Haskell. In the article, "function" means a concrete data object that specifies how to compute something. In Haskell, a function is closer to the mathematical idea of a function. Functions specify relationships between elements of certain types, and then the compiler uses them to create code to do your computation. But there is no obligation for a compiler to create any concrete data structure that corresponds to a function. Often it does in practice, but not always. On the other hand, functions are members of types that are just like any other Haskell type. They are first-class in that sense. Like any type, only certain operations make sense on functions. Strings can be compared to each other for equality and written to a disk, and you can take the logarithm of a float, but none of those operations make sense for functions. In particular, two functions are equal only if they produce the same value for every input, and in general it is impossible for a computer to check that. -Yitz _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On Thu, 27 Dec 2007 11:10:21 +0200, Yitzchak Gale <[hidden email]> wrote:
> On the other hand, functions are members of types > that are just like any other Haskell type. They are > first-class in that sense. I guess that would apply to any typed language. > Like any type, only certain operations make > sense on functions. Strings can be compared to each > other for equality and written to a disk, and you > can take the logarithm of a float, but none of those > operations make sense for functions. In particular, > two functions are equal only if they produce > the same value for every input, and in general it is > impossible for a computer to check that. Yes, but one can store the result of an operation to disk except in the particular case the result happen to be a function. I'm not sure that in Haskell one can say that storing a value of some type to disk is an operation defined on that type. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Yitzchak Gale
------- Forwarded message ------- From: "Cristian Baboi" <[hidden email]> To: "Yitzchak Gale" <[hidden email]> Cc: Subject: Re: [Haskell-cafe] Wikipedia on first-class object Date: Thu, 27 Dec 2007 12:21:44 +0200 I think I found the answer to why functions cannot be written to files. This is by design. Haskell must be free. Enabling writing functions to files, might make it ilegal in some countries. :-) On Thu, 27 Dec 2007 11:10:21 +0200, Yitzchak Gale <[hidden email]> wrote: > Like any type, only certain operations make > sense on functions. Strings can be compared to each > other for equality and written to a disk, and you > can take the logarithm of a float, but none of those > operations make sense for functions. In particular, > two functions are equal only if they produce > the same value for every input, and in general it is > impossible for a computer to check that. > > -Yitz > > > ________ Information from NOD32 ________ > This message was checked by NOD32 Antivirus System for Linux Mail > Servers. > part000.txt - is OK > http://www.eset.com ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
I wrote:
>> On the other hand, functions are members of types >> that are just like any other Haskell type. They are >> first-class in that sense. Cristian Baboi wrote: > I guess that would apply to any typed language. Perhaps. But for many typed languages, it is not practical to use. There may be problems with type safety, or it may create a program that would be considered hard to understand. For example, in Haskell, you create a list of functions just the same way you create a list of anything else. You can then map a value across the functions, or fold the functions together with the composition operator, etc. These are normal, clear idioms in Haskell that could easily appear in any simple program. That is also true for some other functional programming languages, but it is rare for imperative ones. Sometimes there is a particular style within a language that works something like this. For example, you can use C++ with STL that way in a certain sense. Anyway, that is what I think it means when we say that functions are first-class in Haskell. >> Like any type, only certain operations make >> sense on functions. Strings can be compared to each >> other for equality and written to a disk, and you >> can take the logarithm of a float, but none of those >> operations make sense for functions. In particular, >> two functions are equal only if they produce >> the same value for every input, and in general it is >> impossible for a computer to check that. > Yes, but one can store the result of an operation to disk except in the > particular case the result happen to be a function. No, you can only store the result of an operation to disk in the particular case that the result type represents a list of bytes. Otherwise, you have to serialize it first. Happily, Haskell has some cool tools for easily creating serialization methods. And there are a number methods that are already provided in the libraries for many types and for many uses - the Read and Show classes are just one example. But it is not clear at all how you could define a general serialization method for functions. If you can come up with one, please post it to Hackage. :) > I'm not sure that in Haskell one can say that storing a value of some type > to disk is an operation defined on that type. It is. For example: hPutStr :: Handle -> String -> IO () The result type of this function is IO (), which means an IO action. In this case, the semantics of the action are that, when performed, it writes the bytes into a file. Regards, Yitz _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On Thu, 27 Dec 2007 12:40:22 +0200, Yitzchak Gale <[hidden email]> wrote:
> I wrote: >>> On the other hand, functions are members of types >>> that are just like any other Haskell type. They are >>> first-class in that sense. > > Cristian Baboi wrote: >> I guess that would apply to any typed language. > Perhaps. But for many typed languages, it is not > practical to use. There may be problems with type > safety, or it may create a program that would > be considered hard to understand. > > For example, in Haskell, you create a list of functions just > the same way you create a list of anything else. > You can then map a value across the functions, or > fold the functions together with the composition > operator, etc. These are normal, clear idioms > in Haskell that could easily appear in any simple > program. That is also true for some other functional > programming languages, but it is rare for > imperative ones. > > Sometimes there is a particular style within a language > that works something like this. For example, > you can use C++ with STL that way in a certain sense. > Anyway, that is what I think it means when we say that > functions are first-class in Haskell. Ah! You must have been thinking that function in Haskell are members of DATA types. Or, to put it another way, Haskell make no distinction between data types and function types. >>> Like any type, only certain operations make >>> sense on functions. Strings can be compared to each >>> other for equality and written to a disk, and you >>> can take the logarithm of a float, but none of those >>> operations make sense for functions. In particular, >>> two functions are equal only if they produce >>> the same value for every input, and in general it is >>> impossible for a computer to check that. > >> Yes, but one can store the result of an operation to disk except in the >> particular case the result happen to be a function. > No, you can only store the result of an operation to > disk in the particular case that the result type represents > a list of bytes. Otherwise, you have to serialize it first. > Happily, Haskell has some cool tools for easily creating serialization > methods. And there are a number methods that are already > provided in the libraries for many types and for many > uses - the Read and Show classes are just one example. > But it is not clear at all how you could define a general > serialization method for functions. If you can come up > with one, please post it to Hackage. :) Isn't that confusing levels of abstractions ? Of course functions are bytes, 'cause they are already stored as bytes in RAM. >> I'm not sure that in Haskell one can say that storing a value of some >> type >> to disk is an operation defined on that type. > It is. For example: > hPutStr :: Handle -> String -> IO () > > The result type of this function is IO (), which means an > IO action. In this case, the semantics of the action are > that, when performed, it writes the bytes into a file. And this is a property of the type String ? The function hPutStr appears in the definition of the type String ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
Cristian Baboi wrote:
> I think I found the answer to why functions cannot be written to files. > This is by design. Haskell must be free. > Enabling writing functions to files, might make it ilegal in some > countries. :-) Ha, excellent! I imagine that is what Haskell must have been like before they invented the IO monad. It certainly was safer then. -Yitz _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Yitzchak Gale
Thinking about files and types, I recalled that in Pascal files must have
types. On Thu, 27 Dec 2007 12:40:22 +0200, Yitzchak Gale <[hidden email]> wrote: >> I'm not sure that in Haskell one can say that storing a value of some >> type >> to disk is an operation defined on that type. > > It is. For example: > > hPutStr :: Handle -> String -> IO () > > The result type of this function is IO (), which means an > IO action. In this case, the semantics of the action are > that, when performed, it writes the bytes into a file. > ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
Cristian Baboi wrote:
> Ah! You must have been thinking that function in Haskell are members of > DATA types. > Or, to put it another way, Haskell make no distinction between data types > and function types. Yes. I wrote: >>>> Like any type, only certain operations make >>>> sense on functions... >>> Yes, but one can store the result of an operation to disk except in the >>> particular case the result happen to be a function. >> No, you can only store the result of an operation to >> disk in the particular case that the result type represents >> a list of bytes. Otherwise, you have to serialize it first... >> But it is not clear at all how you could define a general >> serialization method for functions. > Isn't that confusing levels of abstractions ? > Of course functions are bytes, 'cause they are already stored as bytes in > RAM. That is just the point. A function in Haskell is an abstraction, not bytes in RAM. The compiler might implement the same function in several places, with different bytes in each place. Or it might decide to combine it into other functions, and not store any bytes in RAM at all for this function. The function itself represents a way of doing a calculation. It is not an object that can do the calculation. >>> I'm not sure that in Haskell one can say that storing a value >>> of some type to disk is an operation defined on that type. >> It is. For example: >> hPutStr :: Handle -> String -> IO () > And this is a property of the type String ? > The function hPutStr appears in the definition of the type String ? Ah, you are thinking of "operation on a type" in the OOP sense. Sorry, I wasn't clear. When I said "only certain operations make sense" on each type, I just meant that there are only certain things you can do with the type. In Haskell, the things you can do with a type are the functions you can define that mention that type in their signature. -Yitz _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Yitzchak Gale
Hello Yitzchak,
Thursday, December 27, 2007, 12:10:21 PM, you wrote: >> http://en.wikipedia.org/wiki/First-class_object >> I'll guess that 5,9,12 does not apply to Haskell functions. you mean 5, 9-12? > In particular, > two functions are equal only if they produce > the same value for every input, and in general it is > impossible for a computer to check that. "for a computer" is superfluous here. people are not smarter than computers and can't do anything that's impossible for computers -- Best regards, Bulat mailto:[hidden email] _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
Hello Cristian,
Thursday, December 27, 2007, 12:19:08 PM, you wrote: > Yes, but one can store the result of an operation to disk except in the > particular case the result happen to be a function. how can values of type T be saved to disk? -- Best regards, Bulat mailto:[hidden email] _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Yitzchak Gale
On Thu, 27 Dec 2007 14:37:51 +0200, Yitzchak Gale <[hidden email]> wrote:
> I wrote: >>>>> Like any type, only certain operations make >>>>> sense on functions... > >>>> Yes, but one can store the result of an operation to disk except in >>>> the >>>> particular case the result happen to be a function. > >>> No, you can only store the result of an operation to >>> disk in the particular case that the result type represents >>> a list of bytes. Otherwise, you have to serialize it first... >>> But it is not clear at all how you could define a general >>> serialization method for functions. > >> Isn't that confusing levels of abstractions ? >> Of course functions are bytes, 'cause they are already stored as bytes >> in >> RAM. > That is just the point. A function in Haskell is an abstraction, > not bytes in RAM. > The compiler might IMPLEMENT the same function in several places, > with different bytes in each place. Or it might decide to combine it > into other functions, and not store any bytes in RAM at all for this > function. See ? > The function itself represents a way of doing a calculation. It is not an > object that can do the calculation. Then trees of functions are ... >>>> I'm not sure that in Haskell one can say that storing a value >>>> of some type to disk is an operation defined on that type. > >>> It is. For example: >>> hPutStr :: Handle -> String -> IO () > >> And this is a property of the type String ? >> The function hPutStr appears in the definition of the type String ? > Ah, you are thinking of "operation on a type" in the OOP sense. > Sorry, I wasn't clear. When I said "only certain operations make > sense" on each type, I just meant that there are only certain > things you can do with the type. In Haskell, the things you can > do with a type are the functions you can define that mention that > type in their signature. How can one define in the language STORAGE of "things" ? Storage of numbers for example ? You said that the TYPE of a function forbids me somehow to store it in a file. Now I understand that not the type forbids me, but the lack of a function with apropriate types. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Bulat Ziganshin-2
On Thu, 27 Dec 2007 14:42:37 +0200, Bulat Ziganshin
<[hidden email]> wrote: > Hello Cristian, > > Thursday, December 27, 2007, 12:19:08 PM, you wrote: > >> Yes, but one can store the result of an operation to disk except in the >> particular case the result happen to be a function. > how can values of type T be saved to disk? I don't know. I'm a beginner in Haskell, and I down't know about T. You mean they cannot ? I was under the impression that the purpose of computers cannot be fulfiled if we cannot get the result of computations out of the computers. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Yitzchak Gale
On Thu, 27 Dec 2007 14:37:51 +0200, Yitzchak Gale <[hidden email]> wrote:
> I wrote: >>>>> Like any type, only certain operations make >>>>> sense on functions... > >>>> Yes, but one can store the result of an operation to disk except in >>>> the >>>> particular case the result happen to be a function. > >>> No, you can only store the result of an operation to >>> disk in the particular case that the result type represents >>> a list of bytes. Otherwise, you have to serialize it first... >>> But it is not clear at all how you could define a general >>> serialization method for functions. > >> Isn't that confusing levels of abstractions ? >> Of course functions are bytes, 'cause they are already stored as bytes >> in >> RAM. > > That is just the point. A function in Haskell is an abstraction, > not bytes in RAM. > > The compiler might implement the same function in several places, > with different bytes in each place. Or it might decide to combine it > into other functions, and not store any bytes in RAM at all for this > function. > > The function itself represents a way of doing a calculation. It is not an > object that can do the calculation. > I think you try to say that the time cannot be stored. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Yitzchak Gale
On Thu, 27 Dec 2007 14:02:36 +0200, Lennart Augustsson
<[hidden email]> wrote: > Comparing functions is certainly possible in Haskell, but there's no > standard function that does it. > If course, it might not terminate, but the same is true for many other > comparable objects in Haskell, e.g., infinite lists (which are > isomorphic to > Nat->T). The list [1 .. ] is a single value in Haskell ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
Hello Cristian,
Thursday, December 27, 2007, 3:51:17 PM, you wrote: >>> Yes, but one can store the result of an operation to disk except in the >>> particular case the result happen to be a function. >> how can values of type T be saved to disk? > I don't know. > I'm a beginner in Haskell, and I down't know about T. here T is any type. you said that values of ANY TYPE can be saved to disk, so show us the way > You mean they cannot ? > I was under the impression that the purpose of computers cannot be > fulfiled if we cannot get the result of computations out of the computers. try to prove that this mean that value of ANY type may be saved to disk -- Best regards, Bulat mailto:[hidden email] _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
On Thu, 27 Dec 2007 16:12:04 +0200, Bulat Ziganshin
<[hidden email]> wrote: > Hello Cristian, > > Thursday, December 27, 2007, 3:51:17 PM, you wrote: > >>>> Yes, but one can store the result of an operation to disk except in >>>> the >>>> particular case the result happen to be a function. > >>> how can values of type T be saved to disk? > >> I don't know. >> I'm a beginner in Haskell, and I down't know about T. > here T is any type. you said that values of ANY TYPE can be saved to > disk, so show us the way The way is toward west. I said except functions. I'll add instances of IO. ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
In reply to this post by Cristian Baboi-2
How about x below: let x=(1:x) in x ? Is x a single value in Haskell ? ------- Forwarded message ------- From: "Cristian Baboi" <[hidden email]> To: "Lennart Augustsson" <[hidden email]> Cc: "[hidden email]" <[hidden email]> Subject: Re: [Haskell-cafe] Wikipedia on first-class object Date: Thu, 27 Dec 2007 16:08:58 +0200 On Thu, 27 Dec 2007 14:02:36 +0200, Lennart Augustsson <[hidden email]> wrote: > Comparing functions is certainly possible in Haskell, but there's no > standard function that does it. > If course, it might not terminate, but the same is true for many other > comparable objects in Haskell, e.g., infinite lists (which are > isomorphic to > Nat->T). The list [1 .. ] is a single value in Haskell ? ________ Information from NOD32 ________ This message was checked by NOD32 Antivirus System for Linux Mail Servers. part000.txt - is OK http://www.eset.com _______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Absolutly. Every expression in Haskell denotes a value.
Now, we've not agreed what "value" means, but to me it is a value. :) -- Lennart On Dec 27, 2007 3:28 PM, Cristian Baboi <
[hidden email]> wrote:
_______________________________________________ Haskell-Cafe mailing list [hidden email] http://www.haskell.org/mailman/listinfo/haskell-cafe |
Free forum by Nabble | Edit this page |