Cornel,
data Sequ a = Empty
| Cons (a,Sequ a)
wieso verwendest Du hier nicht einfach [a]?
If the typevariable "a" would be restricted to range over the typeclass Eq,
the dirty trick of adding the guard
n==n
to the definition of mergesort could be used. But
Hi !
Can anyone tell me whether it's possible to force Haskell to evaluate an
expression strict ? Consider the following Haskell program:
---
module Mergesort where
data Sequ a = Empty
| Cons (a,Sequ a)
Hi !
Can anyone tell me whether it's possible to force Haskell to evaluate an
expression strict ?
Yes, in general it's not possible. That is, I can't write a function
evaluate :: a - a
which will force its argument to WHNF. I can, as you've noted, write
a function:
As others have mentioned, Haskell does not provide a direct means for
strict evaluation. While the class system can be used, the trick of
f x = x | x == x
is not guaranteed to work since == methods defined by the user may not
have the desired strictness property. I could always put
instance
I like John's idea with a class Strict, but I think there should also be
a second class Eval for computing whnf's:
class Strict a where
strict :: a - Bool
class Eval a where
eval :: a - Bool
Example: for Complex we get:
instance Strict a = Strict