[clean-list] How to define subgraph with type signature?

John van Groningen johnvg at cs.ru.nl
Mon Dec 12 16:08:44 MET 2011


On 6-12-2011 21:21, Vag Vagoff wrote:
> ..
> As Dee Mon (http://thedeemon.com) has noticed that subgraph with type
> signature always regarded as function.
>
> For example, in
>
> test1 n = a + a where a = somefunc 0 + 1
>
> 'a' is subgraph and computed only once but in
>
> test2 n = a + a where
> a :: Int
> a = somefunc 0 + 1
>
> 'a' regarded as function and computes twice (i.e. no memoization occurs).
>
> Why is and how to coincide this compiler behavior with the language spec?

The compiler only supports type specifications for functions and 
dynamics. The languages spec calls these FunctionType and DynamicType.

Since 'a' is a function, somefunc will be recomputed each time a is 
called. If you want to prevent recomputation you could define both a 
function and a variable:

test2 n = a + a where
   a = fa

   fa :: Int
   fa = somefunc 0 + 1

Kind regards,

John van Groningen


More information about the clean-list mailing list