Hi,
Is there a way to ensure that functions in a class instance are
treated as top level definitions and not re-evaluated?
For instance if I have this:
class C a where
list :: [a]
instance List a = List [a] where
list = permutations list
How can I ensure that list :: [[X]] is evaluated at
Hello Jonas,
Like other top-level definitions, these instances are considered CAFs
(constant applicative forms), so these instances will in fact usually
be evaluated only once per type X.
import System.IO.Unsafe
class C a where
dflt :: a
instance C Int where
dflt =
Thank you for your response Edward,
You write that it is usually only evaluated once, do you know the
circumstances under which it is evaluated more than once? I have some
examples of this but they are all very large.
The real issue I was having was actually not with a list but with a
memoised
I say usually because while I believe this to be true for the
current implementation of GHC, I don't think we necessary give
this operational guarantee.
But yes, your real problem is that there is a world of difference between
functions and non-functions. You will need to use one of the usual
On 27/06/12 22:41, Facundo Domínguez wrote:
Hi,
The program below when loaded in ghci prints always False, and when
compiled with ghc it prints True. I'm using ghc-7.4.1 and I cannot
quite explain such behavior. Any hints?
Thanks in advance,
Facundo
{-# LANGUAGE GADTs #-}
import
Philip
If you develop a function that does what you want, and want to make it part of
the GHC API, we'd definitely consider including it. But I don't want to
promise to develop something just for you; I'm just too snowed under with other
stuff.
I really think the holes that Thijs is working