-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generalize andM and similar functions #35
Comments
Okay, seems like those functions indeed can be generalized. This seems to work: λ: let andM = foldr (\elem rest -> elem >>= \b -> if b then rest else pure False) (pure True)
λ: :t andM
andM :: (Foldable t, Monad m) => t (m Bool) -> m Bool
λ: andM [Just True, Just False]
Just False
λ: andM [Just True, Just False, Nothing]
Just False
λ: andM [Just True, Nothing, Just False]
Nothing
λ: andM [putStrLn "1" >> pure True, putStrLn "2" >> pure False, putStrLn "3" >> undefined]
1
2
False But don't know how it behaves with space leaks. Using Also I don't know whether it's a good idea: λ: andM (Just [True, False])
[ True , False ]
λ: andM (Just [False])
[ False ]
λ: andM (Just [False]) I expect some bugs after converting |
This is not an issue if we use
Instead of your definition I would just use the original list definition together with |
The only drawback is that version with |
We have #21 for that ;) |
Currently they only work on lists, but can be generalized I suppose.
The text was updated successfully, but these errors were encountered: