[Haskell-beginners] Disjunction

Edward Z. Yang ezyang at MIT.EDU
Fri Dec 10 01:27:26 CET 2010


We can use a standard trick for poly-variadic functions.

    {-# LANGUAGE FlexibleInstances #-}

    class PolyDisj t where
        disj :: Bool -> t

    instance PolyDisj Bool where
        disj x = x

    instance PolyDisj t => PolyDisj (Bool -> t) where
        disj x y = disj (x || y)

And a test:

*Main> disj False False False :: Bool
False
*Main> disj False False False True :: Bool
True

You need to somehow give the expression a type otherwise
it won't know which instance to use.

Edward



More information about the Beginners mailing list