Skip to content

Instantly share code, notes, and snippets.

@qxjit
Created May 1, 2014 15:33
Show Gist options
  • Save qxjit/fd5e177188d7bc6d2336 to your computer and use it in GitHub Desktop.
Save qxjit/fd5e177188d7bc6d2336 to your computer and use it in GitHub Desktop.
Scone Creep Delicious when Scope Creep is not?
data Creep = SomeCreep
data Scope a = SomeScope a
data Scone a = AScone a
data Taste a =
Disgusting
| Yucky
| Edible
| Yummy
| Delicious
class Tasteable a where
taste : Taste a
instance Tasteable Creep where
taste = Edible
instance Tasteable a => Tasteable (Scone a) where
taste = case taste of
Delicious => Delicious
Yummy => Delicious
Edible => Yummy
Yucky => Yucky
Disgusting => Disgusting
instance Tasteable a => Tasteable (Scope a) where
taste = case taste of
Delicious => Edible
Yummy => Yucky
Edible => Disgusting
Yucky => Disgusting
Disgusting => Disgusting
data HasTaste : (a:Type) -> (t:Taste a) -> Type where
-- Prove something is delicious by having the compiler taste it
TryIt : Tasteable a => HasTaste a taste
-- Agree to eat something, but only if it can be proved Delicious
-- ahead of time.
eatThis : a -> HasTaste a Delicious -> String
eatThis _ _ = "Yum, that was Delicious!"
main : IO ()
main = do
-- putStrLn $ eatThis SomeCreep TryIt -- won't compile
-- putStrLn $ eatThis (AScone SomeCreep) TryIt -- won't compile
-- putStrLn $ eatThis (SomeScope SomeCreep) TryIt -- *definitely* won't compile
putStrLn $ eatThis (AScone (AScone SomeCreep)) TryIt -- compiles!
@14to9
Copy link

14to9 commented May 2, 2014

do not want to eat SomeCreep

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment