You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
instanceAllEqts=>Eq (HListts) whereHNil==HNil=True
(a :# as) == (b :# bs) = a == b && as == bs
instance (AllEqts, AllOrdts) =>Ord (HListts) wherecompareHNilHNil=EQcompare (a :# as) (b :# bs) =compare a b <>compare as bs
this will not work
instanceEq (HList '[]) whereHNil==HNil=Trueinstance (Eqt, Eq (HListts)) =>Eq (HList (t ':ts)) where
(a :# as) == (b :# bs) = a == b && as == bs
instance (AllEqts, AllOrdts) =>Ord (HListts) wherecompareHNilHNil=EQcompare (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 (Showt, Show (HListts)) =>Show (HList (t ':ts)) whereshow (x :# xs) =show x <>":#"show xs
should be
instance (Showt, Show (HListts)) =>Show (HList (t ':ts)) whereshow (x :# xs) =show x <>":#"<>show xs
The text was updated successfully, but these errors were encountered:
Require proper Eq instance for Ord instance to work
For exercise
5.3-iii
you need to have theEq
instance forHList
defined in terms ofAll
. This is because the tail ofHList
needs anEq
instance as well as the whole thing when defining theOrd
instance:this will work
this will not work
Typo in solutions
Solution for exercise
5.3-ii
onpg 249
:currently is
should be
The text was updated successfully, but these errors were encountered: