[Haskell-beginners] Using my first map instance
Darren Grant
therealkludgy at gmail.com
Sun Sep 30 09:01:09 CEST 2012
On Sat, Sep 29, 2012 at 2:36 AM, Chaddaï Fouché
<chaddai.fouche at gmail.com> wrote:
> On Sat, Sep 29, 2012 at 2:44 AM, Darren Grant <therealkludgy at gmail.com> wrote:
>> On Fri, Sep 28, 2012 at 4:57 PM, Sean Perry <shaleh at speakeasy.net> wrote:
>>>
>>>
>>> Have you looked at http://www.haskell.org/haskellwiki/Euler_problems/11_to_20#Problem_14?
>>>
>>> The page is full of interesting and fast solutions once you have worked out your own versions.
>>>
>>
>> Hah I didn't know the Haskell Wiki had a Project Euler page. I'll
>> definitely be reviewing with that resource.
>>
>> I notice the use of Array instead of Map, and the careful use of
>> unboxed types. :)
>>
>
> This comment is misleading, there are no unboxed type in this solution
> (maybe the author meant that this compiled down to unboxed types with
> optimisations but the Haskell code definitely use boxed types : Int
> and Word32) though there's a little bit of parallelism involved (could
> be improved).
You are correct. Thanks for pointing out the distinction between
compiler optimizing down to unboxed types and actually declaring these
types in code.
> The use of a functional (immutable) Array here makes perfect sense
> since the keys are effectively an interval of Int... Note that my old
> Array version rely on the laziness of the Array to make it work, this
> is basically dynamic programming where the order of computation
> appears natural but only because laziness means it will be determined
> by the computation itself. This is perfectly functional, no need to
> resort to any imperative style here (or most everywhere in project
> Euler).
>
> --
> Jedaï
This is exactly the kind of recursive function I was trying to set up
with map, but didn't get the algorithm right. I expect the immutable
Array must be much lighter weight than the immutable Map.
Cheers,
Darren
More information about the Beginners
mailing list