Skip to content

Instantly share code, notes, and snippets.

@maurges
Created December 22, 2025 10:28
Show Gist options
  • Select an option

  • Save maurges/0db49b9bc3293927ea2bf39c85eae7fa to your computer and use it in GitHub Desktop.

Select an option

Save maurges/0db49b9bc3293927ea2bf39c85eae7fa to your computer and use it in GitHub Desktop.
Example of two variadic functions in haskell
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