[Haskell-cafe] Re: A bit of a shock - Memoizing functions

Kirk Martinez kirk.martinez at gmail.com
Fri Mar 27 17:26:38 EDT 2009


It seems there is a very close correspondence between data structures and
functions in Haskell.  Your powersOfTwo function, since it gets memoized
automatically (is this the case for all functions of zero arguments?), seems
exactly like a data structure.  This harks back to my Scheme days when we
learned about the close relationship between code and data.

I wonder: does the converse exist?  Haskell data constructors which are
really functions?  How and for what might one use those?

Thanks,
Kirk

On Fri, Mar 27, 2009 at 1:58 PM, GüŸnther Schmidt <gue.schmidt at web.de>wrote:

> Hi Bulat,
>
> that is so cool!
>
> Günther
>
> Bulat Ziganshin schrieb:
>
>> Hello Gü?nther,
>>
>> Friday, March 27, 2009, 11:30:41 PM, you wrote:
>>
>>  Some of the memoizing functions, they actually "remember" stuff
>>> *between* calls?
>>>
>>
>> what i've seen in haskell - functions relying on lazy datastructures
>> that ensure computation on first usage so this looks exactly like as
>> memoizing:
>>
>> power 2 n | n>=0 && n<100 = powersOfTwo!n
>> power x y = x^y
>>
>> powersOfTwo = array (0,99) [2^n | n <- [0..99] ]
>>
>>
>> it's almost exact definition from ghc Prelude
>>
>>
>>
>>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090327/3023184a/attachment.htm


More information about the Haskell-Cafe mailing list