Skip to content

Instantly share code, notes, and snippets.

@mbloms
Created December 23, 2017 23:24
Show Gist options
  • Save mbloms/9dc92fb771e027e3b831c149c4599b3c to your computer and use it in GitHub Desktop.
Save mbloms/9dc92fb771e027e3b831c149c4599b3c to your computer and use it in GitHub Desktop.
Tree parameterized over the root, with an arbitrary type in the child-nodes.
{-# LANGUAGE ExistentialQuantification #-}
import Data.List (unlines)
data HasEq = forall a. (Eq a, Show a) => HasEq a
data AnyIntegral = forall a. Integral a => Integral a
data AnyTree x = forall a b. (Show a, Show b) => Tree x (AnyTree a) (AnyTree b) | Nil
instance Show a => Show (AnyTree a) where
show (Tree x a b) = show (x,(a,b))
show Nil = "Nil"
instance Show HasEq where
show (HasEq x) = "HasEq " ++ show x
--peal :: HasEq -> Int
peal (Integral x) = fromIntegral x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment