
27 Mar
2009
27 Mar
'09
6:11 p.m.
2009/3/27 Kirk Martinez
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.
That's because it is. It's an array whose elements are computed on demand.
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?
Sure. You can use Church encoding to represent any Haskell data type
as a function.
--
Dave Menendez