[Haskell-cafe] Small question

Sebastian Sylvan sebastian.sylvan at gmail.com
Thu Aug 9 14:12:12 EDT 2007


On 09/08/07, Andrew Coppin <andrewcoppin at btinternet.com> wrote:
> Which of these is likely to go faster?
>
>   type Quad = (Bool,Bool)
>
>   foo (r,t) =
>     let
>       x = if r ...
>       y = if t ...
>     in ...
>
>
>
>   data Quad = BL | BR | TL | TR
>
>   foo q =
>     let
>       x = if q == TL | q == TR ...
>       y = if q == BR | q == TR ...
>     in ...
>
>
>
> (Unless somebody has a better idea...)
>
> I'm hoping that the latter one will more more strict / use less space.
> But I don't truely know...
>

Sounds like the perfect candidate for a benchmark, then!

Another tool for your toolbox:

{-#OPTIONS -funbox-strict-fields #-}

data Quad = Quad !Bool !Bool

foo True True = ...
foo True False = ....
... etc...


The GHC option just causese GHC to unbox primitive types when they're
strict in the data type, and the bangs cause them to be strict.

-- 
Sebastian Sylvan
+44(0)7857-300802
UIN: 44640862


More information about the Haskell-Cafe mailing list