Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor bugs in CH5 GADTs #14

Open
JonathanLorimer opened this issue Aug 28, 2019 · 0 comments
Open

Minor bugs in CH5 GADTs #14

JonathanLorimer opened this issue Aug 28, 2019 · 0 comments

Comments

@JonathanLorimer
Copy link
Contributor

Require proper Eq instance for Ord instance to work

For exercise 5.3-iii you need to have the Eq instance for HList defined in terms of All. This is because the tail of HList needs an Eq instance as well as the whole thing when defining the Ord instance:

this will work

instance All Eq ts => Eq (HList ts) where
  HNil == HNil = True
  (a :# as) == (b :# bs) = a == b && as == bs

instance (All Eq ts, All Ord ts) => Ord (HList ts) where
  compare HNil HNil = EQ
  compare (a :# as) (b :# bs) = compare a b <> compare as bs

this will not work

instance Eq (HList '[]) where
  HNil == HNil = True

instance (Eq t, Eq (HList ts)) => Eq (HList (t ': ts)) where
  (a :# as) == (b :# bs) = a == b && as == bs

instance (All Eq ts, All Ord ts) => Ord (HList ts) where
  compare HNil HNil = EQ
  compare (a :# as) (b :# bs) = compare a b <> compare as bs

Typo in solutions

Solution for exercise 5.3-ii on pg 249:

currently is

instance (Show t, Show (HList ts)) => Show (HList (t ': ts)) where
  show (x :# xs) = show x <> ":#" show xs

should be

instance (Show t, Show (HList ts)) => Show (HList (t ': ts)) where
  show (x :# xs) = show x <> ":#" <> show xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant