Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Rebindable if in Haskell

Name: Anonymous 2014-02-19 0:40

{-# LANGUAGE TypeFamilies, RebindableSyntax #-}
import Prelude
class IfThenElse a where
    type ThenT a b
    type ThenT a b = b
    type ElseT a b
    type ElseT a b = b
    ifThenElse :: a -> ThenT a b -> ElseT a b -> b
instance IfThenElse Bool where
    ifThenElse True x _ = x
    ifThenElse False _ y = y
instance IfThenElse (Maybe a) where
    type ThenT (Maybe a) b = a -> b
    type ElseT (Maybe a) b = b
    ifThenElse (Just a) f _ = f a
    ifThenElse Nothing _ b = b

Name: Anonymous 2014-02-19 2:48

mixfix or die

Don't change these.
Name: Email:
Entire Thread Thread List