oneShot (was Re: FoldrW/buildW issues)

2014-10-07 Thread David Feuer
Just for the heck of it, I tried out an implementation of scanl using Joachim Breitner's magical oneShot primitive. Using the test scanlA :: (b - a - b) - b - [a] - [b] scanlA f a bs = build $ \c n - a `c` foldr (\b g x - let b' = f x b in (b' `c` g b')) (const n) bs

Re: oneShot (was Re: FoldrW/buildW issues)

2014-10-07 Thread Sophie Taylor
Wait, isn't call arity analysis meant to do this by itself now? On 7 October 2014 17:05, David Feuer david.fe...@gmail.com wrote: Just for the heck of it, I tried out an implementation of scanl using Joachim Breitner's magical oneShot primitive. Using the test scanlA :: (b - a - b) - b - [a]

Re: oneShot (was Re: FoldrW/buildW issues)

2014-10-07 Thread David Feuer
Yes, and it does a very good job in many cases. In other cases, it's not as good. On Tue, Oct 7, 2014 at 7:59 AM, Sophie Taylor sop...@traumapony.org wrote: Wait, isn't call arity analysis meant to do this by itself now? On 7 October 2014 17:05, David Feuer david.fe...@gmail.com wrote: Just

Re: FoldrW/buildW issues

2014-09-24 Thread David Feuer
On Sep 12, 2014 2:35 PM, Joachim Breitner m...@joachim-breitner.de wrote: I once experimented with a magic oneShot :: (a - b) - (a - b) function, semantically the identity, but tell the compiler not to share the result of the computation. Using that in the definition of foldl-as-foldr, one can

Re: FoldrW/buildW issues

2014-09-24 Thread Joachim Breitner
Hi, Am Mittwoch, den 24.09.2014, 16:37 -0400 schrieb David Feuer: On Sep 12, 2014 2:35 PM, Joachim Breitner m...@joachim-breitner.de wrote: I once experimented with a magic oneShot :: (a - b) - (a - b) function, semantically the identity, but tell the compiler not to share the result of

Re: FoldrW/buildW issues

2014-09-14 Thread David Feuer
Joachim Breitner wrote: Am Samstag, den 13.09.2014, 00:01 -0400 schrieb David Feuer: On Sep 12, 2014 2:35 PM, Joachim Breitner m...@joachim-breitner.de wrote: Interesting. I assumed that some wrap.unwrap=id law would hold, or at least some moral approximation (e.g. disregarding

Re: FoldrW/buildW issues

2014-09-14 Thread Dan Doel
Which scanl wrapper are you referring to? The first one I figured out was quite wrong in certain ways. But I think the new one is less controversial; it's a lot like the reverse one. On Sun, Sep 14, 2014 at 1:03 PM, David Feuer david.fe...@gmail.com wrote: Joachim Breitner wrote: Am Samstag,

Re: FoldrW/buildW issues

2014-09-14 Thread David Feuer
Your scanl wrapper might be right for scanl, but it does not satisfy the condition Joachim proposed. In particular, if we define (!!) :: [a] - Int - a xs !! n | n 0 = error Negative index. | otherwise = foldrW indexWrap indexCons (error Large index.) xs n where indexCons x _ 0 = x

Re: FoldrW/buildW issues

2014-09-14 Thread Joachim Breitner
Hi, Am Sonntag, den 14.09.2014, 14:47 -0400 schrieb David Feuer: Your scanl wrapper might be right for scanl, but it does not satisfy the condition Joachim proposed. In particular, if we define (!!) :: [a] - Int - a xs !! n | n 0 = error Negative index. | otherwise = foldrW

Re: FoldrW/buildW issues

2014-09-13 Thread Joachim Breitner
Hi, Am Samstag, den 13.09.2014, 00:01 -0400 schrieb David Feuer: On Sep 12, 2014 2:35 PM, Joachim Breitner m...@joachim-breitner.de wrote: Interesting. I assumed that some wrap.unwrap=id law would hold, or at least some moral approximation (e.g. disregarding bottoms in an acceptable

Re: FoldrW/buildW issues

2014-09-12 Thread David Feuer
On Sep 12, 2014 2:35 PM, Joachim Breitner m...@joachim-breitner.de wrote: Interesting. I assumed that some wrap.unwrap=id law would hold, or at least some moral approximation (e.g. disregarding bottoms in an acceptable manner). But if the wrappers have to do arbitrary stuff that can