Quick actions

cmd+k|ctrl+k

Navigation

Languages

For loop in Haskell

Snippet info

Language

Haskell

Visibility

public

Author

rightfold

Created

2017-12-08T21:48:39Z

Updated

2017-12-08T21:48:43Z

module Main
  (main) where

for :: Applicative f => a -> (a -> Bool) -> (a -> a) -> (a -> f ()) -> f ()
for initial condition step body
  | condition initial = body initial *> for (step initial) condition step body
  | otherwise = pure ()

main :: IO ()
main =
  for 0 (< 10) (+ 1) $ \i ->
    print i
INFO