-{-
-instance Unfoldable MIMEParams (CIAscii, Text) where
- {-# INLINE insert #-}
- insert p (MIMEParams m)
- = MIMEParams $ insert p m
- {-# INLINE empty #-}
- empty
- = MIMEParams empty
- {-# INLINE singleton #-}
- singleton p
- = MIMEParams $ singleton p
- {-# INLINE insertMany #-}
- insertMany f (MIMEParams m)
- = MIMEParams $ insertMany f m
- {-# INLINE insertManySorted #-}
- insertManySorted f (MIMEParams m)
- = MIMEParams $ insertManySorted f m
--}
+deriveFoldable ∷ Q Cxt → Q Type → Q Exp → Q Exp → Q Dec
+deriveFoldable c ty _ unwrap
+ = do names ← methodNames ''Foldable
+ instanceD c ty $ concatMap (pointfreeMethod exp) names
+ where
+ exp ∷ Name → Q Exp
+ exp name
+ | name ≡ 'fold
+ = [| fold ∘ $unwrap |]
+ | name ≡ 'foldMap
+ = [| (∘ $unwrap) ∘ foldMap |]
+ | name ≡ 'foldr
+ = [| flip flip $unwrap ∘ ((∘) ∘) ∘ foldr |]
+ | name ≡ 'foldl
+ = [| flip flip $unwrap ∘ ((∘) ∘) ∘ foldl |]
+ | name ≡ 'foldr1
+ = [| (∘ $unwrap) ∘ foldr1 |]
+ | name ≡ 'foldl1
+ = [| (∘ $unwrap) ∘ foldl1 |]
+ | name ≡ 'null
+ = [| null ∘ $unwrap |]
+ | name ≡ 'size
+ = [| size ∘ $unwrap |]
+ | name ≡ 'isSingleton
+ = [| isSingleton ∘ $unwrap |]
+ | otherwise
+ = fail $ "deriveFoldable: unknown method: " ⧺ pprint name