-
-
Save bos/525801 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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