Skip to content

Instantly share code, notes, and snippets.

@bos
Created August 15, 2010 18:42
Show Gist options
  • Save bos/525801 to your computer and use it in GitHub Desktop.
Save bos/525801 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, TypeFamilies #-}
module AT where
{- --- ORIGINAL --- -}
data Step s a = Done
| Skip !s
| Yield !a !s
{- --- WITH ATs --- -}
class AStep s a where
data Stepper s a
done :: Stepper s a
skip :: s -> Stepper s a
yield :: a -> s -> Stepper s a
instance (AStep s) Char where
data Stepper s Char = CDone
| CSkip !s
| CYield {-# UNPACK #-} !Char !s
done = CDone
{-# INLINE done #-}
skip = CSkip
{-# INLINE skip #-}
yield = CYield
{-# INLINE yield #-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment