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 <[email protected]>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 > [email protected] > http://www.haskell.org/mailman/listinfo/haskell-cafe >
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
