[Haskell-cafe] Re: FRP for game programming / artifical life simulation

Ben midfield at gmail.com
Fri Apr 30 17:13:32 EDT 2010


FYI i got the lazy pattern match from Patterson's "Programming with
Arrows," so I'm assuming it makes a difference.  (I'll work out a real
example later.)

B

On Fri, Apr 30, 2010 at 8:45 AM, Daniel Fischer
<daniel.is.fischer at web.de> wrote:
> Am Freitag 30 April 2010 17:23:19 schrieb Antoine Latter:
>> On Fri, Apr 30, 2010 at 3:37 AM, Daniel Fischer
>>
>> <daniel.is.fischer at web.de> wrote:
>> > Am Donnerstag 29 April 2010 20:08:00 schrieb Ben:
>> >> A technical question: it seems like the instance of ArrowLoop is too
>> >> strict (this is something I've wondered about in Liu's paper too.)
>> >> Shouldn't it be
>> >>
>> >>  instance ArrowLoop SFAuto where
>> >>      loop (SFAuto s f) = SFAuto s f'
>> >>          where
>> >>            f' (b, s1) = let (~(c, d), s2) = f ((b, d), s1)
>> >>                         in (c, s2)
>> >
>> > Let-bindings are already lazy, so the '~' makes no difference here.
>> > Apart from the readability, both are the same as
>> >
>> > where
>> >  f' (b,s1) = let x = f ((b, snd $ fst x),s1) in (fst $ fst x, snd x)
>>
>> Ben's version is slightly lazier - even though the let binding is
>> lazy, pattern matching is strict.
>>
>> so (let ((x,y).z) = (undefined, "hello") in z) will exception out, but
>> (let (~(x,y),z) = (undefined, "hello") in z) will not.
>>
>> I don't know if you need that level of laziness, though.
>
> Probably not. Although, you're right, if only s2 is ever looked at and not
> c, Ben's version can give a result where the library instance throws an
> exception.
> Was fooled by the use of c in the result.
>
>>
>> Antoine
>
>


More information about the Haskell-Cafe mailing list