[Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
Utrecht Haskell Compiler -- first release, version 1.0.0 The UHC team is happy to announce the first public release of the Utrecht Haskell Compiler (UHC). UHC supports almost all Haskell98 features plus many experimental extensions. The compiler runs on MacOSX, Windows (cygwin), and various Unix flavors. Features: * Multiple backends, including a bytecode interpreter backend and a GRIN based, full program analysing backend, both via C. * Experimental language extensions, some of which have not been implemented before. * Implementation via attribute grammars and other high-level tools. * Ease of experimentation with language variants, thanks to an aspect-oriented internal organisation. Getting started Download -- UHC is available for download as source distribution via the UHC home page: http://www.cs.uu.nl/wiki/UHC Here you will also find instructions to get started. Status of the implementation Like any university project UHC is very much work in progress. We feel that it is mature and stable enough to offer to the public, but much work still needs to be done; hence we welcome contributions by others. UHC grew out of our Haskell compiler project (called Essential Haskell Compiler, or EHC) over the past 5 years. UHC internally is organised as a combination of separate aspects, which makes UHC very suitable to experiment with; it is relatively easy to build compilers for sublanguages, or to generate related tools such as documentation generators, all from the same code base. Extensions to the language can be described separately, and be switched on or of as need arises. Warning --- Although we think that the compiler is stable enough to compile subtantial Haskell programs, we do not recommend yet to use it for any serious development work in Haskell. We ourselves use the GHC as a development platform! We think however that it provides a great platform for experimenting with language implementations, language extensions, etc. Mailing lists - For UHC users and developers respectively: http://mail.cs.uu.nl/mailman/listinfo/uhc-users http://mail.cs.uu.nl/mailman/listinfo/uhc-developers Bug reporting - Please report bugs at: http://code.google.com/p/uhc/issues/list The UHC Team -- Atze Dijkstra, Department of Information and Computing Sciences. /|\ Utrecht University, PO Box 80089, 3508 TB Utrecht, Netherlands. / | \ Tel.: +31-30-2534118/1454 | WWW : http://www.cs.uu.nl/~atze . /--| \ Fax : +31-30-2513971 | Email: a...@cs.uu.nl / |___\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] General function to count list elements?
Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Hello michael, Saturday, April 18, 2009, 6:56:20 PM, you wrote: Is there a general function to count list elements. I'm trying this you should add Eq restriction to type declaration since == operation belomngs to Eq class and your function may work only with types supporting comparision: count :: (Eq a) = a - [a] - Int -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Two functions are equal iff they have the same domain and range and the same outputs for the same inputs. Simple to state, but extremely difficult to implement in a useful way, and impossible to implement in a perfect way. If you had a compiler or algorithm capable of determining function equality, you could use it to prove or disprove arbitrary theorems in mathematics. Regards, John A. De Goes N-BRAIN, Inc. The Evolution of Collaboration http://www.n-brain.net|877-376-2724 x 101 On Apr 18, 2009, at 9:39 AM, Eugene Kirpichov wrote: Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Well, this definition, although correct, contradicts the OP's claim that \x-x /= \y-if 1==1 then y else undefined :) I'm leading the OP to the thought that necessity Eq constraint and lack of an Eq instance for functions (and thus non-existence of a universally polymorphic 'count' function) is something dictated by the nature of the world, not by the nature of Haskell. 2009/4/18 John A. De Goes j...@n-brain.net: Two functions are equal iff they have the same domain and range and the same outputs for the same inputs. Simple to state, but extremely difficult to implement in a useful way, and impossible to implement in a perfect way. If you had a compiler or algorithm capable of determining function equality, you could use it to prove or disprove arbitrary theorems in mathematics. Regards, John A. De Goes N-BRAIN, Inc. The Evolution of Collaboration http://www.n-brain.net | 877-376-2724 x 101 On Apr 18, 2009, at 9:39 AM, Eugene Kirpichov wrote: Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. To compare two functions in C, I would compare their machine addresses. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
2009/4/18 michael rice nowg...@yahoo.com: I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t That's not the functions being compared, but the memory addresses of the code implementing them. If your goal is comparing functions to answer a question Are these two values indistinguishable?, equal? doesn't help you, because it may answer 'false' even if these two values are indistinguishable from a mathematical point of view. but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. Again, this is first-class support for memory addresses of code representing functions. To compare two functions in C, I would compare their machine addresses. Why would you need that at all? Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: General function to count list elements?
The problem is that you must note in the type signature the fact that 'a' must be a member of typeclass Eq in order to be able to use == count :: (Eq a) = a - [a] - Int count x ys = length (filter (== x) ys) JP michael rice wrote: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Also, having such an equality test will introduce ambiguity and unsoundness, prevent the compiler from certain optimizations etc. For example, should (+5)==(+5) be true or false? What about let f=(+5) in f==f? If you are declaring the first equality to be true, then you are implying that the compiler must implement extensional equality, which is impossible. Consider let x=5 in (+x)==(+x). If you are declaring it to be false, then you are breaking referential transparency: you can't anymore safely substitute let x=v in E with E[x:=v]. C doesn't have these problems because it never declared that it has any form of referential transparency or mathematical soundness; neither does it have closures and currying. Scheme explicitly declares that the result of equal? on functions can't be relied upon. Haskell takes the mathematically sound path: it simply outlaws ambiguities. 2009/4/18 michael rice nowg...@yahoo.com: I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. To compare two functions in C, I would compare their machine addresses. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re[2]: [Haskell-cafe] General function to count list elements?
Hello michael, Saturday, April 18, 2009, 8:27:45 PM, you wrote: so you can use Scheme to derive theorem proofs. useful for exams! :) I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. To compare two functions in C, I would compare their machine addresses. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Best regards, Bulatmailto:bulat.zigans...@gmail.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Haskell is referentially transparent. This enables a whole host of program reasoning and compiler optimization techniques that you can't get in languages without this property; it's hard to explain why it is good until you've been bitten by code that *isn't*. One big consequence of referential transparency is that a whole host of complicated optimizations in other languages are replaced with simple inlining. So one question is, what does this program do? main = print (count id [id]) The compiler might decide to inline the first id: main = print (count (\x - x) [id]) which then, if we are comparing machine addresses, means they are not equal. I am sure you agree that code that stops working depending on the optimization settings of the compiler is a scary thing! In scheme, which is not referentially transparent, there are several equality primitives. One checks object identity, whereas another goes into the depths of any structure it is passed and compares the innards. In Haskell, there is *no* concept of object identity. It just doesn't exist! This means there is no observable difference between 1 and (length [ hello ]). There's no observable difference between const and (\x y - x). In order to make this work, but still be able to use == (which everyone wants), == requires its arguments to be of a type that is comparable for equality; that's what the error message from ghci is saying: On Sat, Apr 18, 2009 at 9:27 AM, michael rice nowg...@yahoo.com wrote: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 -- ryan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
To compare two functions in C, I would compare their machine addresses. Why would you need that at all? How would *you* do it? Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 12:39 PM 2009/4/18 michael rice nowg...@yahoo.com: I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t That's not the functions being compared, but the memory addresses of the code implementing them. If your goal is comparing functions to answer a question Are these two values indistinguishable?, equal? doesn't help you, because it may answer 'false' even if these two values are indistinguishable from a mathematical point of view. but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. Again, this is first-class support for memory addresses of code representing functions. To compare two functions in C, I would compare their machine addresses. Why would you need that at all? Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of `length', namely `(filter (== x) ys)' In the expression: length (filter (== x) ys) Failed, modules loaded: none. Prelude = Not sure what it's trying to tell me other than I need an (Eq a) somewhere. Michael ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru -- Eugene Kirpichov Web IR developer, market.yandex.ru ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
2009/4/18 michael rice nowg...@yahoo.com: To compare two functions in C, I would compare their machine addresses. Why would you need that at all? How would *you* do it? Do what? As for comparing functions, I would not do it at all, because comparing functions makes no sense: one way of comparison (extensional equality) is not implementable, whereas the other (object identity) breaks referential transparency and is impossible to reason about and generally doesn't have a single reason to work correctly at all. Object identity has no reason to exist in a language without mutable objects, like Haskell. That's probably the key. As for implementing the count function, I would implement it in the way that people already suggested to you: by putting a constraint onto its type, namely a constraint that makes it polymorphic *over types whose values can be compared for equality*, t.i. over members of the Eq class. This is perfectly correct and does not cause any mathematical unsoundness. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 12:39 PM 2009/4/18 michael rice nowg...@yahoo.com: I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t That's not the functions being compared, but the memory addresses of the code implementing them. If your goal is comparing functions to answer a question Are these two values indistinguishable?, equal? doesn't help you, because it may answer 'false' even if these two values are indistinguishable from a mathematical point of view. but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. Again, this is first-class support for memory addresses of code representing functions. To compare two functions in C, I would compare their machine addresses. Why would you need that at all? Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32 Possible fix: add (Eq a) to the context of the type signature for `count' In the first argument of `filter', namely `(== x)' In the first argument of
Re: [Haskell-cafe] General function to count list elements?
On Sat, Apr 18, 2009 at 11:11 AM, michael rice nowg...@yahoo.com wrote: To compare two functions in C, I would compare their machine addresses. Why would you need that at all? How would *you* do it? Do what? What is the problem? No, I don't mean comparing two functions. I rather mean, why are you comparing these functions? What question is the comparison answering, and how are you using that answer? Is address comparison really what your code wants, or do you want some stronger property? Luke Michael --- On *Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com* wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 12:39 PM 2009/4/18 michael rice nowg...@yahoo.comhttp://mc/compose?to=nowg...@yahoo.com : I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t That's not the functions being compared, but the memory addresses of the code implementing them. If your goal is comparing functions to answer a question Are these two values indistinguishable?, equal? doesn't help you, because it may answer 'false' even if these two values are indistinguishable from a mathematical point of view. but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ http://www.haskell.org/ghc/%C2%A0:? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. Again, this is first-class support for memory addresses of code representing functions. To compare two functions in C, I would compare their machine addresses. Why would you need that at all? Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.comhttp://mc/compose?to=ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.comhttp://mc/compose?to=ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.comhttp://mc/compose?to=nowg...@yahoo.com Cc: haskell-cafe@haskell.orghttp://mc/compose?to=haskell-c...@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.comhttp://mc/compose?to=nowg...@yahoo.com : Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.comhttp://mc/compose?to=ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.comhttp://mc/compose?to=ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.comhttp://mc/compose?to=nowg...@yahoo.com Cc: haskell-cafe@haskell.orghttp://mc/compose?to=haskell-c...@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.comhttp://mc/compose?to=nowg...@yahoo.com : Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count GHCi, version 6.10.1: http://www.haskell.org/ghc/ http://www.haskell.org/ghc/%C2%A0:? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. [1 of 1] Compiling Main ( count.hs, interpreted ) count.hs:2:29: Could not deduce (Eq a) from the context () arising from a use of `==' at count.hs:2:29-32
Re: [Haskell-cafe] General function to count list elements?
I wasn't comparing functions, you were. I was just trying to answer your questions. I had a count function that worked fine for an enum type, but thought why not go polymorphic with it. So I changed it and got the error I originally inquired about. Thanks. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 1:18 PM 2009/4/18 michael rice nowg...@yahoo.com: To compare two functions in C, I would compare their machine addresses. Why would you need that at all? How would *you* do it? Do what? As for comparing functions, I would not do it at all, because comparing functions makes no sense: one way of comparison (extensional equality) is not implementable, whereas the other (object identity) breaks referential transparency and is impossible to reason about and generally doesn't have a single reason to work correctly at all. Object identity has no reason to exist in a language without mutable objects, like Haskell. That's probably the key. As for implementing the count function, I would implement it in the way that people already suggested to you: by putting a constraint onto its type, namely a constraint that makes it polymorphic *over types whose values can be compared for equality*, t.i. over members of the Eq class. This is perfectly correct and does not cause any mathematical unsoundness. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 12:39 PM 2009/4/18 michael rice nowg...@yahoo.com: I know functions can be compared in Scheme Welcome to DrScheme, version 4.1 [3m]. Language: Swindle; memory limit: 128 megabytes. (equal? equal? equal?) #t That's not the functions being compared, but the memory addresses of the code implementing them. If your goal is comparing functions to answer a question Are these two values indistinguishable?, equal? doesn't help you, because it may answer 'false' even if these two values are indistinguishable from a mathematical point of view. but apparently not in Haskell [mich...@localhost ~]$ ghci GHCi, version 6.10.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer ... linking ... done. Loading package base ... linking ... done. Prelude (==) (==) (==) interactive:1:0: No instance for (Eq (a - a - Bool)) arising from a use of `==' at interactive:1:0-13 Possible fix: add an instance declaration for (Eq (a - a - Bool)) In the expression: (==) (==) (==) In the definition of `it': it = (==) (==) (==) Prelude though I'm new at Haskell and may not be posing the question properly. I would think a language with 1st-class support for functions would certainly include comparing them. Again, this is first-class support for memory addresses of code representing functions. To compare two functions in C, I would compare their machine addresses. Why would you need that at all? Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:39 AM Could you then provide an example of two functions that *are* equal, or, even better, a definition of equality for arbitrary functions? Since Haskell may be compiled into C, this must be a definition that is implementable in C. 2009/4/18 michael rice nowg...@yahoo.com: Though I haven't tried it out, it's trying to use my function to count functions. The first argument is the identity function. The second argument is a list of a different form of the identity function. Though the two identity functions, given the same input, would produce the same output, I doubt they would be equal. So my guess at an answer would be zero. Michael --- On Sat, 4/18/09, Eugene Kirpichov ekirpic...@gmail.com wrote: From: Eugene Kirpichov ekirpic...@gmail.com Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 11:03 AM What should count (\x - x) (replicate 10 (\y - if 1==1 then y else undefined)) return? 2009/4/18 michael rice nowg...@yahoo.com: Is there a general function to count list elements. I'm trying this count :: a - [a] - Int count x ys = length (filter (== x) ys) with this error upon loading = [mich...@localhost ~]$ ghci count
Re: [Haskell-cafe] General function to count list elements?
Michael, I had a count function that worked fine for an enum type, but thought why not go polymorphic with it. So I changed it and got the error I originally inquired about. For variety, I'll go a slightly different direction. If you generalize count to use any predicate, instead of always equality... gcount :: (a - a - Bool) - a - [a] - Int gcount pred x0 xs = length (filter (pred x0) xs) count = gcount (==) This will work with any type that you can write a predicate for with the type (a - a - Bool). I can even use this with functions, if I'm careful. ghci gcount (\f g - True) (*2) [id,(const 1),(*3)] 3 ghci gcount (\f g - f 1 == g 1) (^2) [id,(const 1),(*3)] 2 By the way, do you see why everyone's bothing you about comparing functions? The type you gave count, which didn't have an Eq constraint, was an assertion that you could compare two values of *any* type. If there's a type that's not comparable, then count's type was wrong. Functions are the canonical example of an incomparable type. When you're bored some time, read a bit about the Curry-Howard correspondence. It's interesting, even if (like me) you don't grok all of its implications. Regards, John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] General function to count list elements?
Hi John, Yes, I see now what the hullabaloo was about. I've only been hacking Haskell for a few weeks, so I'm still seeing the forest rather than the trees. But I'm coming along. Thanks. Michael --- On Sat, 4/18/09, John Dorsey hask...@colquitt.org wrote: From: John Dorsey hask...@colquitt.org Subject: Re: [Haskell-cafe] General function to count list elements? To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Saturday, April 18, 2009, 2:36 PM Michael, I had a count function that worked fine for an enum type, but thought why not go polymorphic with it. So I changed it and got the error I originally inquired about. For variety, I'll go a slightly different direction. If you generalize count to use any predicate, instead of always equality... gcount :: (a - a - Bool) - a - [a] - Int gcount pred x0 xs = length (filter (pred x0) xs) count = gcount (==) This will work with any type that you can write a predicate for with the type (a - a - Bool). I can even use this with functions, if I'm careful. ghci gcount (\f g - True) (*2) [id,(const 1),(*3)] 3 ghci gcount (\f g - f 1 == g 1) (^2) [id,(const 1),(*3)] 2 By the way, do you see why everyone's bothing you about comparing functions? The type you gave count, which didn't have an Eq constraint, was an assertion that you could compare two values of *any* type. If there's a type that's not comparable, then count's type was wrong. Functions are the canonical example of an incomparable type. When you're bored some time, read a bit about the Curry-Howard correspondence. It's interesting, even if (like me) you don't grok all of its implications. Regards, John ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
On Sat, Apr 18, 2009 at 9:03 AM, a...@cs.uu.nl wrote: Utrecht Haskell Compiler -- first release, version 1.0.0 The UHC team is happy to announce the first public release of the Utrecht Haskell Compiler (UHC). UHC supports almost all Haskell98 features plus many experimental extensions. The compiler runs on MacOSX, Windows (cygwin), and various Unix flavors. Features: * Multiple backends, including a bytecode interpreter backend and a GRIN based, full program analysing backend, both via C. * Experimental language extensions, some of which have not been implemented before. * Implementation via attribute grammars and other high-level tools. * Ease of experimentation with language variants, thanks to an aspect-oriented internal organisation. Getting started Download -- UHC is available for download as source distribution via the UHC home page: http://www.cs.uu.nl/wiki/UHC Here you will also find instructions to get started. Status of the implementation Like any university project UHC is very much work in progress. We feel that it is mature and stable enough to offer to the public, but much work still needs to be done; hence we welcome contributions by others. UHC grew out of our Haskell compiler project (called Essential Haskell Compiler, or EHC) over the past 5 years. UHC internally is organised as a combination of separate aspects, which makes UHC very suitable to experiment with; it is relatively easy to build compilers for sublanguages, or to generate related tools such as documentation generators, all from the same code base. Extensions to the language can be described separately, and be switched on or of as need arises. Warning --- Although we think that the compiler is stable enough to compile subtantial Haskell programs, we do not recommend yet to use it for any serious development work in Haskell. We ourselves use the GHC as a development platform! We think however that it provides a great platform for experimenting with language implementations, language extensions, etc. Mailing lists - For UHC users and developers respectively: http://mail.cs.uu.nl/mailman/listinfo/uhc-users http://mail.cs.uu.nl/mailman/listinfo/uhc-developers Bug reporting - Please report bugs at: http://code.google.com/p/uhc/issues/list The UHC Team -- Atze Dijkstra, Department of Information and Computing Sciences. /|\ Utrecht University, PO Box 80089, 3508 TB Utrecht, Netherlands. / | \ Tel.: +31-30-2534118/1454 | WWW : http://www.cs.uu.nl/~atze . /--| \ Fax : +31-30-2513971 | Email: a...@cs.uu.nl / |___\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe After running ./configure on my Intel Mac (running OS 10.5.6 with GHC 6.10), I try to run make uhc and get the following: $ make uhc src/ruler2/files.mk:34: build/ruler2/files-ag-d-dep.mk: No such file or directory src/ruler2/files.mk:35: build/ruler2/files-ag-s-dep.mk: No such file or directory mkdir -p build/shuffle ; \ --module=CDoc -dr -Psrc/shuffle/ -o build/shuffle/CDoc.hs src/shuffle/CDoc.ag /bin/sh: --module=CDoc: command not found make: Failed to remake makefile `build/ruler2/files-ag-s-dep.mk'. make: Failed to remake makefile `build/ruler2/files-ag-d-dep.mk'. make EHC_VARIANT=`echo install/101/bin/ehc | sed -n -e 's+install/\([0-9_]*\)/bin/ehc.*+\1+p'` ehc-variant src/ruler2/files.mk:34: build/ruler2/files-ag-d-dep.mk: No such file or directory src/ruler2/files.mk:35: build/ruler2/files-ag-s-dep.mk: No such file or directory mkdir -p build/shuffle ; \ --module=CDoc -dr -Psrc/shuffle/ -o build/shuffle/CDoc.hs src/shuffle/CDoc.ag /bin/sh: --module=CDoc: command not found make[1]: Failed to remake makefile `build/ruler2/files-ag-s-dep.mk'. make[1]: Failed to remake makefile `build/ruler2/files-ag-d-dep.mk'. make EHC_VARIANT_RULER_SEL=((101=HS)).(expr.base patexpr.base tyexpr.base decl.base).(e.int e.char e.var e.con e.str p.str) \ ehc-variant-dflt src/ruler2/files.mk:34: build/ruler2/files-ag-d-dep.mk: No such file or directory src/ruler2/files.mk:35: build/ruler2/files-ag-s-dep.mk: No such file or directory mkdir -p build/shuffle ; \ --module=CDoc -dr -Psrc/shuffle/ -o build/shuffle/CDoc.hs src/shuffle/CDoc.ag /bin/sh: --module=CDoc: command not found make[2]: Failed to remake makefile `build/ruler2/files-ag-s-dep.mk'. make[2]: Failed to remake makefile `build/ruler2/files-ag-d-dep.mk'. make[1]: *** [ehc-variant] Error 2 make: *** [install/101/bin/ehc] Error 2 This is fairly bewildering. Am I the only one seeing errors like this? Thanks, Antoine Also: $ make --version GNU Make 3.81 Copyright (C) 2006 Free
[Haskell-cafe] Announce: A pragmatic Haskell .NET interop layer, 0.4.0
A new version of a Haskell .NET interop layer, hs-dotnet, has just been released and is now available for download, http://haskell.forkIO.com/dotnet It lets you access .NET functionality from Haskell and vice versa. Tool support is included in this release to aid such interop. The new version includes development done since the start of the year. Apart from rewriting the internals completely to put it all on a sounder footing, this release includes proper support for .NET generic types (classes and interfaces), mapping them naturally on to Haskell parameterized types. The support for generics enables for instance mixed Haskell-.NET LINQ programming; see the distribution for examples of this along with some other interesting applications of the hs-dotnet interop layer. enjoy --sigbjorn ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Zippers for gui elements?
Hi all, I need to control some gui elements, ie. stuff like when dis button is clicked make dat one inactive. Some time ago, wish I'd remember where, I read about using Zippers for that sort of thing. Does anybody know where I might have read that? Günther ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
On 18 Apr 2009, at 22:44, Antoine Latter wrote: On Sat, Apr 18, 2009 at 9:03 AM, a...@cs.uu.nl wrote: Utrecht Haskell Compiler -- first release, version 1.0.0 The UHC team is happy to announce the first public release of the Utrecht Haskell Compiler (UHC). UHC supports almost all Haskell98 features plus many experimental extensions. The compiler runs on MacOSX, Windows (cygwin), and various Unix flavors. Features: * Multiple backends, including a bytecode interpreter backend and a GRIN based, full program analysing backend, both via C. * Experimental language extensions, some of which have not been implemented before. * Implementation via attribute grammars and other high-level tools. * Ease of experimentation with language variants, thanks to an aspect-oriented internal organisation. Getting started Download -- UHC is available for download as source distribution via the UHC home page: http://www.cs.uu.nl/wiki/UHC Here you will also find instructions to get started. Status of the implementation Like any university project UHC is very much work in progress. We feel that it is mature and stable enough to offer to the public, but much work still needs to be done; hence we welcome contributions by others. UHC grew out of our Haskell compiler project (called Essential Haskell Compiler, or EHC) over the past 5 years. UHC internally is organised as a combination of separate aspects, which makes UHC very suitable to experiment with; it is relatively easy to build compilers for sublanguages, or to generate related tools such as documentation generators, all from the same code base. Extensions to the language can be described separately, and be switched on or of as need arises. Warning --- Although we think that the compiler is stable enough to compile subtantial Haskell programs, we do not recommend yet to use it for any serious development work in Haskell. We ourselves use the GHC as a development platform! We think however that it provides a great platform for experimenting with language implementations, language extensions, etc. Mailing lists - For UHC users and developers respectively: http://mail.cs.uu.nl/mailman/listinfo/uhc-users http://mail.cs.uu.nl/mailman/listinfo/uhc-developers Bug reporting - Please report bugs at: http://code.google.com/p/uhc/issues/list The UHC Team -- Atze Dijkstra, Department of Information and Computing Sciences. /|\ Utrecht University, PO Box 80089, 3508 TB Utrecht, Netherlands. / | \ Tel.: +31-30-2534118/1454 | WWW : http://www.cs.uu.nl/ ~atze . /--| \ Fax : +31-30-2513971 | Email: a...@cs.uu.nl / | ___\ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe After running ./configure on my Intel Mac (running OS 10.5.6 with GHC 6.10), I try to run make uhc and get the following: $ make uhc src/ruler2/files.mk:34: build/ruler2/files-ag-d-dep.mk: No such file or directory src/ruler2/files.mk:35: build/ruler2/files-ag-s-dep.mk: No such file or directory mkdir -p build/shuffle ; \ --module=CDoc -dr -Psrc/shuffle/ -o build/shuffle/CDoc.hs src/ shuffle/CDoc.ag /bin/sh: --module=CDoc: command not found make: Failed to remake makefile `build/ruler2/files-ag-s-dep.mk'. make: Failed to remake makefile `build/ruler2/files-ag-d-dep.mk'. make EHC_VARIANT=`echo install/101/bin/ehc | sed -n -e 's+install/\([0-9_]*\)/bin/ehc.*+\1+p'` ehc-variant src/ruler2/files.mk:34: build/ruler2/files-ag-d-dep.mk: No such file or directory src/ruler2/files.mk:35: build/ruler2/files-ag-s-dep.mk: No such file or directory mkdir -p build/shuffle ; \ --module=CDoc -dr -Psrc/shuffle/ -o build/shuffle/CDoc.hs src/ shuffle/CDoc.ag /bin/sh: --module=CDoc: command not found make[1]: Failed to remake makefile `build/ruler2/files-ag-s-dep.mk'. make[1]: Failed to remake makefile `build/ruler2/files-ag-d-dep.mk'. make EHC_VARIANT_RULER_SEL=((101=HS)).(expr.base patexpr.base tyexpr.base decl.base).(e.int e.char e.var e.con e.str p.str) \ ehc-variant-dflt src/ruler2/files.mk:34: build/ruler2/files-ag-d-dep.mk: No such file or directory src/ruler2/files.mk:35: build/ruler2/files-ag-s-dep.mk: No such file or directory mkdir -p build/shuffle ; \ --module=CDoc -dr -Psrc/shuffle/ -o build/shuffle/CDoc.hs src/ shuffle/CDoc.ag /bin/sh: --module=CDoc: command not found make[2]: Failed to remake makefile `build/ruler2/files-ag-s-dep.mk'. make[2]: Failed to remake makefile `build/ruler2/files-ag-d-dep.mk'. make[1]: *** [ehc-variant] Error 2 make: *** [install/101/bin/ehc] Error 2 This is fairly bewildering. Am I the only one seeing errors like this? This looks like the same error I got – see bug report 1 in the bug
Re: [Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
On Sat, Apr 18, 2009 at 4:38 PM, Thomas Davie tom.da...@gmail.com wrote: This looks like the same error I got – see bug report 1 in the bug database – the configure script reports that you have uuagc even if you don't – cabal install it, reconfigure, and you should be on your way. Second thing to watch for – it depends on fgl, but this isn't caught by the configure script. Apparently a user install of uuagc and fgl isn't good enough. Fun to know. Antoine ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
Antoine Latter aslat...@gmail.com wrote: On Sat, Apr 18, 2009 at 4:38 PM, Thomas Davie tom.da...@gmail.com wrote: This looks like the same error I got ___ see bug report 1 in the bug database ___ the configure script reports that you have uuagc even if you don't ___ cabal install it, reconfigure, and you should be on your way. Second thing to watch for ___ it depends on fgl, but this isn't caught by the configure script. Apparently a user install of uuagc and fgl isn't good enough. Fun to know. Do you have your $PATH set to include $HOME/.cabal/bin ? -- (c) this sig last receiving data processing entity. Inspect headers for copyright history. All rights reserved. Copying, hiring, renting, performance and/or quoting of this signature prohibited. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
On 19 Apr 2009, at 00:31, Antoine Latter wrote: On Sat, Apr 18, 2009 at 4:38 PM, Thomas Davie tom.da...@gmail.com wrote: This looks like the same error I got – see bug report 1 in the bug database – the configure script reports that you have uuagc even if you don't – cabal install it, reconfigure, and you should be on your way. Second thing to watch for – it depends on fgl, but this isn't caught by the configure script. Apparently a user install of uuagc and fgl isn't good enough. Fun to know. I've found user installs don't work at all on OS X, various people in #haskell were rather surprised to discover this, so apparently it's not the default behavior on other platforms. It really rather makes cabal install rather odd – because it doesn't actually install anything you can use without providing extra options! Bob___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ANNOUNCE: Utrecht Haskell Compiler (UHC) -- first release
I've learnt (the hard way) not to trust user installs at all. On Sun, Apr 19, 2009 at 12:41 AM, Thomas Davie tom.da...@gmail.com wrote: On 19 Apr 2009, at 00:31, Antoine Latter wrote: On Sat, Apr 18, 2009 at 4:38 PM, Thomas Davie tom.da...@gmail.com wrote: This looks like the same error I got – see bug report 1 in the bug database – the configure script reports that you have uuagc even if you don't – cabal install it, reconfigure, and you should be on your way. Second thing to watch for – it depends on fgl, but this isn't caught by the configure script. Apparently a user install of uuagc and fgl isn't good enough. Fun to know. I've found user installs don't work at all on OS X, various people in #haskell were rather surprised to discover this, so apparently it's not the default behavior on other platforms. It really rather makes cabal install rather odd – because it doesn't actually install anything you can use without providing extra options! Bob___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe