[Haskell-cafe] ANN: loop - fast for loops

Niklas Hambüchen mail at nh2.me
Sun Jul 20 12:24:42 UTC 2014


Hey,

I have nothing against bikeshedding contributions :)

For now I don't want to break backwards compatibility with renames, but
if more idomatic things like forM_ [1..n] keep not being optimised as
well and more people start using loop as a package, agreeing on a set of
names that people find nicest would be good. Maybe you can put your
suggestion into a github issue, so that we don't forget about them?

On 20/07/14 07:26, wren romano wrote:
> How do you feel about bikeshedding contributions? The following seems
> more idiomatic to me:
> 
>     -- Formerly @forLoopFold at . This is the primitive notion, so it
> should have the simplest name.
>     loop  ::  a -> (a -> Bool) -> (a -> a) -> b -> (b -> a -> b) -> b
> 
>     -- This one is new. We want to implement it directly instead of
> using 'loop' for the same reasons that we want to implement 'loopM_'
> directly.
>     loopM :: Monad m => a -> (a -> Bool) -> (a -> a) -> b -> (b -> a
> -> m b) -> m b
> 
>     -- Formerly @forLoop@
>     loopM_ :: Monad m => a -> (a -> Bool) -> (a -> a) -> (a -> m ()) -> m ()
> 
>     loopFromTo :: (Eq a, Enum a) => a -> a -> b -> (b -> a -> b) -> b
>     loopFromTo start stop = loop start (stop ==) succ
> 
>     loopNumFromTo :: (Eq a, Num a) => a -> a -> b -> (b -> a -> b) -> b
>     loopNumFromTo start stop = loop start (stop ==) (1+)
> 
>     loopFromToM :: (Eq a, Enum a) => a -> a -> b -> (b -> a -> m b) -> m b
>     loopFromToM start stop = loopM start (stop ==) succ
> 
>     loopNumFromToM :: (Eq a, Num a) => a -> a -> b -> (b -> a -> m b) -> m b
>     loopNumFromToM start stop = loopM start (stop ==) (1+)
> 
>     loopFromToM_ :: (Eq a, Enum a) => a -> a -> (a -> m ()) -> m ()
>     loopFromToM_ start stop = loopM_ start (stop ==) succ
> 
>     loopNumFromToM_ :: (Eq a, Num a) => a -> a -> (a -> m ()) -> m ()
>     loopNumFromToM_ start stop = loopM_ start (stop ==) (1+)
> 
> the loopNum* names are pretty arbitrary/crappy, but using the *FromTo,
> *M, and *M_ names is far more idiomatic.
> 


More information about the Haskell-Cafe mailing list