Created
December 22, 2025 10:28
-
-
Save maurges/0db49b9bc3293927ea2bf39c85eae7fa to your computer and use it in GitHub Desktop.
Example of two variadic functions in haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Control.Applicative (liftA2) | |
| class Printf r where | |
| printf' :: IO () -> r | |
| instance Printf (IO ()) where | |
| printf' prev = prev >> putStr "\n" | |
| instance Printf a => Printf (Integer -> a) where | |
| printf' prev = \x -> printf' (prev >> putStr (show x)) | |
| printf :: Printf r => r | |
| printf = printf' (pure ()) | |
| class PolyOr a r where | |
| polyOr :: (a -> Bool) -> r | |
| instance PolyOr a (a -> Bool) where | |
| polyOr f a = f a | |
| instance PolyOr a r => PolyOr a ((a -> Bool) -> r) where | |
| polyOr f g = polyOr (liftA2 (||) f g) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment