Skip to content

Commit

Permalink
[#265] Make SuperComposition less brittle
Browse files Browse the repository at this point in the history
* Use overlapping instances instead of incoherent ones. Fixes #265.

* Make the first argument of `...` a function unconditionally, before
  instance selection. This can theoretically improve inference slightly,
  though it probably doesn't have much impact in practice.
  • Loading branch information
treeowl committed May 9, 2022
1 parent 86b30df commit 716654d
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Universum/VarArg.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module Universum.VarArg
-- >>> import Data.List (zip5)

-- | This type class allows to implement variadic composition operator.
class SuperComposition a b c | a b -> c where
class SuperComposition x y b r | x y b -> r where
-- | Allows to apply function to result of another function with multiple
-- arguments.
--
Expand All @@ -45,16 +45,16 @@ class SuperComposition a b c | a b -> c where
-- disappear due to very general inferred type. However, functions without type
-- specification but with applied @INLINE@ pragma are fast again.
--
(...) :: a -> b -> c
(...) :: (x -> y) -> b -> r

infixl 8 ...

instance {-# INCOHERENT #-} (a ~ c, r ~ b) =>
SuperComposition (a -> b) c r where
instance {-# OVERLAPPABLE #-} (x ~ b, y ~ r) =>
SuperComposition x y b r where
f ... g = f g
{-# INLINE (...) #-}

instance {-# INCOHERENT #-} (SuperComposition (a -> b) d r1, r ~ (c -> r1)) =>
SuperComposition (a -> b) (c -> d) r where
instance {-# OVERLAPPING #-} (SuperComposition x y d r1, r ~ (c -> r1)) =>
SuperComposition x y (c -> d) r where
(f ... g) c = f ... g c
{-# INLINE (...) #-}

0 comments on commit 716654d

Please sign in to comment.