gelisam / surjective

An output coverage checker
https://hackage.haskell.org/package/surjective
11 stars 2 forks source link

Proper support for polymorphism #10

Open gelisam opened 6 years ago

gelisam commented 6 years ago

Template Haskell has some strange limitations. The following works:

listMaybes :: Num a => [a] -> [Maybe a]
listMaybes xs = $$(surjective
  [||\covers -> ((\x -> covers $ \(Just _) -> Just x) <$> xs)
             ++ [covers $ \Nothing -> Nothing]
  ||])

But the following doesn't:

-- error: No instance for (Num a) arising from the literal ‘0’
listMaybes :: Num a => [a] -> [Maybe a]
listMaybes xs = $$(surjective
  [||\covers -> ((\x -> covers $ \(Just _) -> Just x) <$> xs)
             ++ [covers $ \Nothing -> Nothing]
             ++ [Just 0]
  ||])