overload 0.1.0.2 → 0.1.0.3
raw patch · 3 files changed
+21/−1 lines, 3 files
Files
- overload.cabal +1/−1
- src/Overload.hs +13/−0
- src/Overload/Example.hs +7/−0
overload.cabal view
@@ -1,5 +1,5 @@ name: overload-version: 0.1.0.2+version: 0.1.0.3 synopsis: Finite overloading description: Provides a mechanism for finite overloading homepage: https://gitlab.com/LukaHorvat/overload
src/Overload.hs view
@@ -41,6 +41,8 @@ import Data.Function import Control.Monad import Language.Haskell.TH.ExpandSyns +import Data.List (tails) +import Data.Semigroup ((<>)) import Overload.Normal import Overload.TypeTree @@ -74,6 +76,17 @@ t' -> (n, [], t')) seeds <- forM triplets $ \(_, _, t) -> normalizeTypeTree <$> typeToTypeTree (const (Var Nothing)) Just t + let pairs = concatMap ( \case + x : xs -> concatMap (\y -> [(x, y), (y, x)]) xs + [] -> [] ) (tails seeds) + let errs = filter (uncurry isMoreGeneralThan) pairs + unless (null errs) $ do + forM_ errs $ \(x, y) -> + reportError + $ "Type " <> showTypeTree x <> " is more general than " <> showTypeTree y <> ".\n" + <> "There is no way to construct a set of non-overlapping instances.\n" + <> "To fix this, make the first type more specific." + fail "Not all types are distinguishable." concat <$> zipWithM insts (allDeciders seeds) triplets
src/Overload/Example.hs view
@@ -30,3 +30,10 @@ g3 = undefined overload "g" ['g1, 'g2, 'g3] + +h1 :: Maybe a +h1 = Nothing +h2 :: Maybe Int +h2 = Just 2 + +-- overload "h" ['h1, 'h2]