Re: [Haskell-cafe] Re: General function to count list elements?

2009-04-20 Thread Peter Verswyvelen
A solution with enums would severely suffer from the expression problem...
One would need to extent the enums every time one needs to support a new
function. Maybe could be solved with type classes, don't know.
On Mon, Apr 20, 2009 at 3:57 PM, Achim Schneider bars...@web.de wrote:

 Lennart Augustsson lenn...@augustsson.net wrote:

  On Sun, Apr 19, 2009 at 10:43 PM, Peter Verswyvelen
  bugf...@gmail.com wrote:
   For example, suppose you have a predicate a - Bool, and a list of
   these predicates [a - Bool], but you want to remove all functions
   that are obviously equal in the C way from the list for
   optimization... Okay big hack, and one could do this already with
   reallyUnsafePtrEquality# I guess...
 
  And when the need gets big enough you pull out StablePtr and use
  that. :)
 
 Waaagh! Don't give him ideas, he's going to do it... Make yourself an
 enum, generate your list, nub it, then transform it to a list of
 functions. Always do everything with the least information sanely
 feasible, and a function is more information than a value, even if you
 can't get at it, anymore.


 --
 (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

___
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?

2009-04-20 Thread Achim Schneider
Lennart Augustsson lenn...@augustsson.net wrote:

 On Sun, Apr 19, 2009 at 10:43 PM, Peter Verswyvelen
 bugf...@gmail.com wrote:
  For example, suppose you have a predicate a - Bool, and a list of
  these predicates [a - Bool], but you want to remove all functions
  that are obviously equal in the C way from the list for
  optimization... Okay big hack, and one could do this already with
  reallyUnsafePtrEquality# I guess... 

 And when the need gets big enough you pull out StablePtr and use
 that. :)
 
Waaagh! Don't give him ideas, he's going to do it... Make yourself an
enum, generate your list, nub it, then transform it to a list of
functions. Always do everything with the least information sanely
feasible, and a function is more information than a value, even if you
can't get at it, anymore.


-- 
(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] Re: General function to count list elements?

2009-04-20 Thread Luke Palmer
On Mon, Apr 20, 2009 at 7:57 AM, Achim Schneider bars...@web.de wrote:

 Lennart Augustsson lenn...@augustsson.net wrote:

  On Sun, Apr 19, 2009 at 10:43 PM, Peter Verswyvelen
  bugf...@gmail.com wrote:
   For example, suppose you have a predicate a - Bool, and a list of
   these predicates [a - Bool], but you want to remove all functions
   that are obviously equal in the C way from the list for
   optimization... Okay big hack, and one could do this already with
   reallyUnsafePtrEquality# I guess...
 
  And when the need gets big enough you pull out StablePtr and use
  that. :)
 
 Waaagh! Don't give him ideas, he's going to do it...


Nah, I don't think so.

I think, even after all this mess, we've been relatively clear that Eq is
how you do it.

Luke
___
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?

2009-04-19 Thread Achim Schneider
Peter Verswyvelen bugf...@gmail.com wrote:

 Sometimes I do miss the pragmatic C solution:- two function pointers
 that are equal surely represent the same functions (although in C
 nothing is really sure ;)

In haskell, they would, but C doesn't give you the same guarantee:

int evil = 0;

int wicked( int i_dare_you ) {
return i_dare_you + (++evil);
}

Clearly, wicked and wicked are the same function, but they surely
aren't indistinguishable, at least if you happen to call them.

-- 
(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



[Haskell-cafe] Re: General function to count list elements?

2009-04-18 Thread Juan Pedro Bolivar Puente
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