Skip to content

Instantly share code, notes, and snippets.

@PPKFS
Created March 22, 2021 14:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PPKFS/45626a1a7642afaf1817853d3b55819a to your computer and use it in GitHub Desktop.
Save PPKFS/45626a1a7642afaf1817853d3b55819a to your computer and use it in GitHub Desktop.
-- how I can do it
universe = fromList $ [("cat", ["animal"]), ("dog", ["animal"]), ("catdog", ["cat", "dog"])
isType x x = True
isType x y = case lookup universe x of
Nothing -> False
Just supertypes -> if y in supertypes then True else any (`isType` y) supertypes
-- "cat" `isType` "animal" True
-- "cat" `isType` "catdog" False
-- "catdog" `isType` "animal" True
-- "ctadog" `isType` "anmial" False, but should be a compile error..
-- what I'd like to do, weird pseudocode
type family? Types
data Cat
data Dog
data CatDog
data Animal
universe = fromList $ [(Cat, [Animal]), (Dog, [Animal])...
Ctadog `isType` Anmial is now a typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment