20-CS-4003-001 Organization of Programming Languages Fall 2017
Functors

Lambda calculus, Type theory, Formal semantics, Program analysis

Prev     Next     All lectures           Code

Basics

{- another example -}
data Colors = Red | Green | Blue

class YesNo a 
  where  
    yesno :: a -> Bool    {- all instantiations of this function are below -}

instance YesNo Int where  
  yesno 0 = False  
  yesno _ = True  

instance YesNo [a] where  
  yesno [] = False  
  yesno _ = True 

instance YesNo Colors where
  yesno Red = True
  yesno _ = False

instance YesNo (Maybe m) where
  yesno (Just _) = True
  yesno Nothing = False