Oops, somehow that reply by Scott Turner (which coincidentally
contained the same example) hadn't appeared for me yet :)
Anyway, seconded :)
On 26/06/05, Cale Gibbard [EMAIL PROTECTED] wrote:
Well, the case of the built-in numeric types is somewhat different,
but most functions automatically
Am Samstag, 25. Juni 2005 21:22 schrieb Josh Hoyt:
Hello,
I'm a new Haskeller, and I'm running into a problem attempting to
declare certain types as instances. I was attempting something that's
effectively equivalent to:
class Foo a
instance Foo (Either b b)
but GHC complains:
Scott Turner wrote:
It's still possible to use fold and get short circuiting with good memory
usage.
upTo pred = foldr (\a - \xs - if pred a then [a] else a:xs) []
prodList = foldl' (*) 1 . upTo (== 0)
It might be considered cheating, but AFAICT the test for ==0 needs to be
separated
On Sun, 26 Jun 2005, Daniel Fischer wrote:
Am Samstag, 25. Juni 2005 21:22 schrieb Josh Hoyt:
Hello,
I'm a new Haskeller, and I'm running into a problem attempting to
declare certain types as instances. I was attempting something that's
effectively equivalent to:
class Foo a
Am Sonntag, 26. Juni 2005 06:06 schrieb Scott Turner:
On 2005 June 25 Saturday 17:49, [EMAIL PROTECTED] wrote:
Simplified:
prodList xs = foldl (*) 1 xs
But my original at least made some provision for short circuiting the
whole operation if the list contained a 0. As far as I can
On Sun, 26 Jun 2005, Daniel Fischer wrote:
m x y = if x==0 then 0 else x*y
Plain
foldr m 1
does fine, in fact much better than
foldl' (*) 1 . upTo (== 0),
both in hugs and ghc, regarding speed and memory usage.
E.g.
foldr m 1 [a,b,c]
means
m a (m b (m c 1)))
That is, it is
Lennart Augustsson [EMAIL PROTECTED] wrote:
snip
There are, of course, type systems where my program works fine.
O'Haskell is an example of a language with such a type system. In
O'Haskell the Either type is defined like this:
data Left a = Left a
data Right a = Right a
Daniel Brown [EMAIL PROTECTED] wrote:
Jonathan Cast wrote:
Lennart Augustsson [EMAIL PROTECTED] wrote:
foo :: Either a b - Either () b
foo (Left _) = Left ()
foo x@(Right _) = x
Since Haskell type checking doesn't use the information gained by
pattern matching to refine types we