Skip to content

Instantly share code, notes, and snippets.

@masaeedu
Last active July 28, 2017 16:02
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 masaeedu/30adb29ad4b1d0cfd1ae65aaedf7ad9e to your computer and use it in GitHub Desktop.
Save masaeedu/30adb29ad4b1d0cfd1ae65aaedf7ad9e to your computer and use it in GitHub Desktop.
newtype Visitor e r = Visitor { visit :: e -> r }
data Employee = PermanentEmployee | Contractor
xmlvisitor :: Visitor Employee String
xmlvisitor = Visitor { visit = visitEmp }
where visitEmp PermanentEmployee = "<employee />"
visitEmp Contractor = "<contractor />"
class Visitee e where
accept :: e -> Visitor e r -> r
instance Visitee Employee where
accept e v = visit v e
main = do putStrLn (accept PermanentEmployee xmlvisitor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment