{-# LANGUAGE RecordWildCards #-}
{- | Utility types for type inference
-}

{-# language OverloadedStrings #-}
{-# options_ghc  -Wno-orphans #-}

module Language.Giml.Types.Infer.Types where

import qualified Data.Text as T
import qualified Data.Set as S
import Control.Monad.Except

import Utils
import Language.Giml.Syntax.Ast
import qualified Language.Giml.Syntax.Parser as Parser

-- for debugging purposes --
import Prettyprinter (Pretty, Doc, pretty, (<+>), align)
import Language.Giml.Pretty (ppType, ppSourcePos, braced', render)

---------------
-- * Types

-- | The annotation of the input
type InputAnn = Parser.Ann

-- | The annotation of the output: the input + the type
data Ann
  = Ann
    { Ann -> SourcePos
annInput :: InputAnn
    , Ann -> Type
annType :: Type
    }
  deriving (Int -> Ann -> ShowS
[Ann] -> ShowS
Ann -> String
(Int -> Ann -> ShowS)
-> (Ann -> String) -> ([Ann] -> ShowS) -> Show Ann
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Ann] -> ShowS
$cshowList :: [Ann] -> ShowS
show :: Ann -> String
$cshow :: Ann -> String
showsPrec :: Int -> Ann -> ShowS
$cshowsPrec :: Int -> Ann -> ShowS
Show, Ann -> Ann -> Bool
(Ann -> Ann -> Bool) -> (Ann -> Ann -> Bool) -> Eq Ann
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ann -> Ann -> Bool
$c/= :: Ann -> Ann -> Bool
== :: Ann -> Ann -> Bool
$c== :: Ann -> Ann -> Bool
Eq, Eq Ann
Eq Ann
-> (Ann -> Ann -> Ordering)
-> (Ann -> Ann -> Bool)
-> (Ann -> Ann -> Bool)
-> (Ann -> Ann -> Bool)
-> (Ann -> Ann -> Bool)
-> (Ann -> Ann -> Ann)
-> (Ann -> Ann -> Ann)
-> Ord Ann
Ann -> Ann -> Bool
Ann -> Ann -> Ordering
Ann -> Ann -> Ann
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Ann -> Ann -> Ann
$cmin :: Ann -> Ann -> Ann
max :: Ann -> Ann -> Ann
$cmax :: Ann -> Ann -> Ann
>= :: Ann -> Ann -> Bool
$c>= :: Ann -> Ann -> Bool
> :: Ann -> Ann -> Bool
$c> :: Ann -> Ann -> Bool
<= :: Ann -> Ann -> Bool
$c<= :: Ann -> Ann -> Bool
< :: Ann -> Ann -> Bool
$c< :: Ann -> Ann -> Bool
compare :: Ann -> Ann -> Ordering
$ccompare :: Ann -> Ann -> Ordering
Ord, Typeable Ann
Typeable Ann
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Ann -> c Ann)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Ann)
-> (Ann -> Constr)
-> (Ann -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Ann))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ann))
-> ((forall b. Data b => b -> b) -> Ann -> Ann)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r)
-> (forall u. (forall d. Data d => d -> u) -> Ann -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Ann -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Ann -> m Ann)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ann -> m Ann)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Ann -> m Ann)
-> Data Ann
Ann -> DataType
Ann -> Constr
(forall b. Data b => b -> b) -> Ann -> Ann
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Ann -> u
forall u. (forall d. Data d => d -> u) -> Ann -> [u]
forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r
forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ann
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ann -> c Ann
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ann)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ann)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Ann -> m Ann
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Ann -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Ann -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Ann -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Ann -> [u]
gmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r
$cgmapQr :: forall r r'.
(r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r
gmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r
$cgmapQl :: forall r r'.
(r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ann -> r
gmapT :: (forall b. Data b => b -> b) -> Ann -> Ann
$cgmapT :: (forall b. Data b => b -> b) -> Ann -> Ann
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ann)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Ann)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ann)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Ann)
dataTypeOf :: Ann -> DataType
$cdataTypeOf :: Ann -> DataType
toConstr :: Ann -> Constr
$ctoConstr :: Ann -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ann
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Ann
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ann -> c Ann
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Ann -> c Ann
Data)

type TypeErrorA = ([InputAnn], TypeError)

-- | The type of type errors.
data TypeError
  = TypeMismatch Type Type
  | UnboundVar Var
  | InfiniteType TypeVar Type
  | ArityMismatch Type Type
  | UnboundTypeVarsInType (Datatype InputAnn)
  | DuplicateTypeVarsInSig (Datatype InputAnn)
  | DuplicateConstrs (Datatype InputAnn)
  | DuplicateConstrs2 [(Constr, (VariantSig InputAnn, VariantSig InputAnn))]
  | NoSuchVariant Constr
  | RecordDiff Type Type [Label] [Label]
  | VariantDiff Type Type [Constr] [Constr]
  | NotARecord Type
  | NotAVariant Type
  | DuplicateVarsInPattern Pattern
  deriving (Int -> TypeError -> ShowS
[TypeError] -> ShowS
TypeError -> String
(Int -> TypeError -> ShowS)
-> (TypeError -> String)
-> ([TypeError] -> ShowS)
-> Show TypeError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypeError] -> ShowS
$cshowList :: [TypeError] -> ShowS
show :: TypeError -> String
$cshow :: TypeError -> String
showsPrec :: Int -> TypeError -> ShowS
$cshowsPrec :: Int -> TypeError -> ShowS
Show, TypeError -> TypeError -> Bool
(TypeError -> TypeError -> Bool)
-> (TypeError -> TypeError -> Bool) -> Eq TypeError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypeError -> TypeError -> Bool
$c/= :: TypeError -> TypeError -> Bool
== :: TypeError -> TypeError -> Bool
$c== :: TypeError -> TypeError -> Bool
Eq, Eq TypeError
Eq TypeError
-> (TypeError -> TypeError -> Ordering)
-> (TypeError -> TypeError -> Bool)
-> (TypeError -> TypeError -> Bool)
-> (TypeError -> TypeError -> Bool)
-> (TypeError -> TypeError -> Bool)
-> (TypeError -> TypeError -> TypeError)
-> (TypeError -> TypeError -> TypeError)
-> Ord TypeError
TypeError -> TypeError -> Bool
TypeError -> TypeError -> Ordering
TypeError -> TypeError -> TypeError
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TypeError -> TypeError -> TypeError
$cmin :: TypeError -> TypeError -> TypeError
max :: TypeError -> TypeError -> TypeError
$cmax :: TypeError -> TypeError -> TypeError
>= :: TypeError -> TypeError -> Bool
$c>= :: TypeError -> TypeError -> Bool
> :: TypeError -> TypeError -> Bool
$c> :: TypeError -> TypeError -> Bool
<= :: TypeError -> TypeError -> Bool
$c<= :: TypeError -> TypeError -> Bool
< :: TypeError -> TypeError -> Bool
$c< :: TypeError -> TypeError -> Bool
compare :: TypeError -> TypeError -> Ordering
$ccompare :: TypeError -> TypeError -> Ordering
Ord)

-- | Represents the constraints on types we collect during the elaboration phase.
data Constraint
  -- | The two type should be equal.
  = Equality Type Type
  deriving (Int -> Constraint -> ShowS
[Constraint] -> ShowS
Constraint -> String
(Int -> Constraint -> ShowS)
-> (Constraint -> String)
-> ([Constraint] -> ShowS)
-> Show Constraint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Constraint] -> ShowS
$cshowList :: [Constraint] -> ShowS
show :: Constraint -> String
$cshow :: Constraint -> String
showsPrec :: Int -> Constraint -> ShowS
$cshowsPrec :: Int -> Constraint -> ShowS
Show, Constraint -> Constraint -> Bool
(Constraint -> Constraint -> Bool)
-> (Constraint -> Constraint -> Bool) -> Eq Constraint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Constraint -> Constraint -> Bool
$c/= :: Constraint -> Constraint -> Bool
== :: Constraint -> Constraint -> Bool
$c== :: Constraint -> Constraint -> Bool
Eq, Eq Constraint
Eq Constraint
-> (Constraint -> Constraint -> Ordering)
-> (Constraint -> Constraint -> Bool)
-> (Constraint -> Constraint -> Bool)
-> (Constraint -> Constraint -> Bool)
-> (Constraint -> Constraint -> Bool)
-> (Constraint -> Constraint -> Constraint)
-> (Constraint -> Constraint -> Constraint)
-> Ord Constraint
Constraint -> Constraint -> Bool
Constraint -> Constraint -> Ordering
Constraint -> Constraint -> Constraint
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Constraint -> Constraint -> Constraint
$cmin :: Constraint -> Constraint -> Constraint
max :: Constraint -> Constraint -> Constraint
$cmax :: Constraint -> Constraint -> Constraint
>= :: Constraint -> Constraint -> Bool
$c>= :: Constraint -> Constraint -> Bool
> :: Constraint -> Constraint -> Bool
$c> :: Constraint -> Constraint -> Bool
<= :: Constraint -> Constraint -> Bool
$c<= :: Constraint -> Constraint -> Bool
< :: Constraint -> Constraint -> Bool
$c< :: Constraint -> Constraint -> Bool
compare :: Constraint -> Constraint -> Ordering
$ccompare :: Constraint -> Constraint -> Ordering
Ord, Typeable Constraint
Typeable Constraint
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Constraint -> c Constraint)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Constraint)
-> (Constraint -> Constr)
-> (Constraint -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c Constraint))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c Constraint))
-> ((forall b. Data b => b -> b) -> Constraint -> Constraint)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> Constraint -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> Constraint -> r)
-> (forall u. (forall d. Data d => d -> u) -> Constraint -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> Constraint -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> Constraint -> m Constraint)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Constraint -> m Constraint)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Constraint -> m Constraint)
-> Data Constraint
Constraint -> DataType
Constraint -> Constr
(forall b. Data b => b -> b) -> Constraint -> Constraint
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Constraint -> u
forall u. (forall d. Data d => d -> u) -> Constraint -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Constraint -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Constraint -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Constraint
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Constraint -> c Constraint
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Constraint)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Constraint)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Constraint -> m Constraint
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Constraint -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Constraint -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Constraint -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Constraint -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Constraint -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Constraint -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Constraint -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Constraint -> r
gmapT :: (forall b. Data b => b -> b) -> Constraint -> Constraint
$cgmapT :: (forall b. Data b => b -> b) -> Constraint -> Constraint
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Constraint)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Constraint)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Constraint)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Constraint)
dataTypeOf :: Constraint -> DataType
$cdataTypeOf :: Constraint -> DataType
toConstr :: Constraint -> Constr
$ctoConstr :: Constraint -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Constraint
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Constraint
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Constraint -> c Constraint
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Constraint -> c Constraint
Data)

-- | A constraint with the input annotation.
type ConstraintA = (Constraint, InputAnn)

-- | A @Set@ of constraints.
type Constraints = Set ConstraintA

-- | A mapping from type variable to types. Also contains the source position for error reporting.
--   This is the output of the constraint solving phase.
type Substitution
  = Map TypeVar (InputAnn, Type)

-- | Relevant information about a data constructor.
data VariantSig a
  = VariantSig
    { forall a. VariantSig a -> [TypeVar]
vsVars :: [TypeVar]
    , forall a. VariantSig a -> Type
vsDatatype :: Type
    , forall a. VariantSig a -> Maybe Type
vsPayloadTemplate :: Maybe Type
    , forall a. VariantSig a -> a
vsAnn :: a
    }
  deriving (Int -> VariantSig a -> ShowS
[VariantSig a] -> ShowS
VariantSig a -> String
(Int -> VariantSig a -> ShowS)
-> (VariantSig a -> String)
-> ([VariantSig a] -> ShowS)
-> Show (VariantSig a)
forall a. Show a => Int -> VariantSig a -> ShowS
forall a. Show a => [VariantSig a] -> ShowS
forall a. Show a => VariantSig a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [VariantSig a] -> ShowS
$cshowList :: forall a. Show a => [VariantSig a] -> ShowS
show :: VariantSig a -> String
$cshow :: forall a. Show a => VariantSig a -> String
showsPrec :: Int -> VariantSig a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> VariantSig a -> ShowS
Show, VariantSig a -> VariantSig a -> Bool
(VariantSig a -> VariantSig a -> Bool)
-> (VariantSig a -> VariantSig a -> Bool) -> Eq (VariantSig a)
forall a. Eq a => VariantSig a -> VariantSig a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: VariantSig a -> VariantSig a -> Bool
$c/= :: forall a. Eq a => VariantSig a -> VariantSig a -> Bool
== :: VariantSig a -> VariantSig a -> Bool
$c== :: forall a. Eq a => VariantSig a -> VariantSig a -> Bool
Eq, Eq (VariantSig a)
Eq (VariantSig a)
-> (VariantSig a -> VariantSig a -> Ordering)
-> (VariantSig a -> VariantSig a -> Bool)
-> (VariantSig a -> VariantSig a -> Bool)
-> (VariantSig a -> VariantSig a -> Bool)
-> (VariantSig a -> VariantSig a -> Bool)
-> (VariantSig a -> VariantSig a -> VariantSig a)
-> (VariantSig a -> VariantSig a -> VariantSig a)
-> Ord (VariantSig a)
VariantSig a -> VariantSig a -> Bool
VariantSig a -> VariantSig a -> Ordering
VariantSig a -> VariantSig a -> VariantSig a
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {a}. Ord a => Eq (VariantSig a)
forall a. Ord a => VariantSig a -> VariantSig a -> Bool
forall a. Ord a => VariantSig a -> VariantSig a -> Ordering
forall a. Ord a => VariantSig a -> VariantSig a -> VariantSig a
min :: VariantSig a -> VariantSig a -> VariantSig a
$cmin :: forall a. Ord a => VariantSig a -> VariantSig a -> VariantSig a
max :: VariantSig a -> VariantSig a -> VariantSig a
$cmax :: forall a. Ord a => VariantSig a -> VariantSig a -> VariantSig a
>= :: VariantSig a -> VariantSig a -> Bool
$c>= :: forall a. Ord a => VariantSig a -> VariantSig a -> Bool
> :: VariantSig a -> VariantSig a -> Bool
$c> :: forall a. Ord a => VariantSig a -> VariantSig a -> Bool
<= :: VariantSig a -> VariantSig a -> Bool
$c<= :: forall a. Ord a => VariantSig a -> VariantSig a -> Bool
< :: VariantSig a -> VariantSig a -> Bool
$c< :: forall a. Ord a => VariantSig a -> VariantSig a -> Bool
compare :: VariantSig a -> VariantSig a -> Ordering
$ccompare :: forall a. Ord a => VariantSig a -> VariantSig a -> Ordering
Ord, Typeable (VariantSig a)
Typeable (VariantSig a)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> VariantSig a -> c (VariantSig a))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (VariantSig a))
-> (VariantSig a -> Constr)
-> (VariantSig a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (VariantSig a)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (VariantSig a)))
-> ((forall b. Data b => b -> b) -> VariantSig a -> VariantSig a)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> VariantSig a -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> VariantSig a -> r)
-> (forall u. (forall d. Data d => d -> u) -> VariantSig a -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> VariantSig a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a))
-> Data (VariantSig a)
VariantSig a -> DataType
VariantSig a -> Constr
(forall b. Data b => b -> b) -> VariantSig a -> VariantSig a
forall {a}. Data a => Typeable (VariantSig a)
forall a. Data a => VariantSig a -> DataType
forall a. Data a => VariantSig a -> Constr
forall a.
Data a =>
(forall b. Data b => b -> b) -> VariantSig a -> VariantSig a
forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> VariantSig a -> u
forall a u.
Data a =>
(forall d. Data d => d -> u) -> VariantSig a -> [u]
forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VariantSig a)
forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VariantSig a -> c (VariantSig a)
forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (VariantSig a))
forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VariantSig a))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> VariantSig a -> u
forall u. (forall d. Data d => d -> u) -> VariantSig a -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VariantSig a)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VariantSig a -> c (VariantSig a)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (VariantSig a))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VariantSig a))
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
$cgmapMo :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
$cgmapMp :: forall a (m :: * -> *).
(Data a, MonadPlus m) =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
$cgmapM :: forall a (m :: * -> *).
(Data a, Monad m) =>
(forall d. Data d => d -> m d) -> VariantSig a -> m (VariantSig a)
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> VariantSig a -> u
$cgmapQi :: forall a u.
Data a =>
Int -> (forall d. Data d => d -> u) -> VariantSig a -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> VariantSig a -> [u]
$cgmapQ :: forall a u.
Data a =>
(forall d. Data d => d -> u) -> VariantSig a -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
$cgmapQr :: forall a r r'.
Data a =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
$cgmapQl :: forall a r r'.
Data a =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VariantSig a -> r
gmapT :: (forall b. Data b => b -> b) -> VariantSig a -> VariantSig a
$cgmapT :: forall a.
Data a =>
(forall b. Data b => b -> b) -> VariantSig a -> VariantSig a
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VariantSig a))
$cdataCast2 :: forall a (t :: * -> * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VariantSig a))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (VariantSig a))
$cdataCast1 :: forall a (t :: * -> *) (c :: * -> *).
(Data a, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (VariantSig a))
dataTypeOf :: VariantSig a -> DataType
$cdataTypeOf :: forall a. Data a => VariantSig a -> DataType
toConstr :: VariantSig a -> Constr
$ctoConstr :: forall a. Data a => VariantSig a -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VariantSig a)
$cgunfold :: forall a (c :: * -> *).
Data a =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VariantSig a)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VariantSig a -> c (VariantSig a)
$cgfoldl :: forall a (c :: * -> *).
Data a =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VariantSig a -> c (VariantSig a)
Data)

vsToTypeScheme :: VariantSig a -> Type
vsToTypeScheme :: forall a. VariantSig a -> Type
vsToTypeScheme VariantSig{a
[TypeVar]
Maybe Type
Type
vsAnn :: a
vsPayloadTemplate :: Maybe Type
vsDatatype :: Type
vsVars :: [TypeVar]
vsAnn :: forall a. VariantSig a -> a
vsPayloadTemplate :: forall a. VariantSig a -> Maybe Type
vsDatatype :: forall a. VariantSig a -> Type
vsVars :: forall a. VariantSig a -> [TypeVar]
..} =
  let
    addscheme :: Type -> Type
addscheme
      | [TypeVar] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [TypeVar]
vsVars = Type -> Type
forall a. a -> a
id
      | Bool
otherwise = [TypeVar] -> Type -> Type
TypeScheme [TypeVar]
vsVars
  in
    Type -> Type
addscheme (Type -> Type) -> Type -> Type
forall a b. (a -> b) -> a -> b
$
      Type -> (Type -> Type) -> Maybe Type -> Type
forall b a. b -> (a -> b) -> Maybe a -> b
maybe
        Type
vsDatatype
        (\Type
t -> [Type] -> Type -> Type
typeFun [Type
t] Type
vsDatatype)
        Maybe Type
vsPayloadTemplate

-- * Utils

-- | Throw an error with annotation.
throwErr :: MonadError TypeErrorA m => [InputAnn] -> TypeError -> m a
throwErr :: forall (m :: * -> *) a.
MonadError TypeErrorA m =>
[SourcePos] -> TypeError -> m a
throwErr [SourcePos]
ann TypeError
err = TypeErrorA -> m a
forall e (m :: * -> *) a. MonadError e m => e -> m a
throwError ([SourcePos]
ann, TypeError
err)

-- | Retrieve the type of an expression. Will explode when used on a non @EAnnotated@ node.
getType :: Expr Ann -> Type
getType :: Expr Ann -> Type
getType = Ann -> Type
annType (Ann -> Type) -> (Expr Ann -> Ann) -> Expr Ann -> Type
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Expr Ann -> Ann
forall a. Show a => Expr a -> a
getExprAnn

-- * Pretty printing

ppShow :: Pretty ann => Functor f => Show (f Text) => f ann -> Text
ppShow :: forall ann (f :: * -> *).
(Pretty ann, Functor f, Show (f Text)) =>
f ann -> Text
ppShow = f Text -> Text
forall a. Show a => a -> Text
pShow (f Text -> Text) -> (f ann -> f Text) -> f ann -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ann -> Text) -> f ann -> f Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text) -> (ann -> Doc Any) -> ann -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ann -> Doc Any
forall a ann. Pretty a => a -> Doc ann
pretty)

ppShowC :: Constraint -> Text
ppShowC :: Constraint -> Text
ppShowC = Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text) -> (Constraint -> Doc Any) -> Constraint -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constraint -> Doc Any
forall ann. Constraint -> Doc ann
ppConstraint

ppShowCs :: Show (f Text) => Functor f => f Constraint -> Text
ppShowCs :: forall (f :: * -> *).
(Show (f Text), Functor f) =>
f Constraint -> Text
ppShowCs = f Text -> Text
forall a. Show a => a -> Text
pShow (f Text -> Text)
-> (f Constraint -> f Text) -> f Constraint -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Constraint -> Text) -> f Constraint -> f Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text) -> (Constraint -> Doc Any) -> Constraint -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constraint -> Doc Any
forall ann. Constraint -> Doc ann
ppConstraint)

ppShowCAss :: Set ConstraintA -> Text
ppShowCAss :: Set ConstraintA -> Text
ppShowCAss = Set Text -> Text
forall a. Show a => a -> Text
pShow (Set Text -> Text)
-> (Set ConstraintA -> Set Text) -> Set ConstraintA -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ConstraintA -> Text) -> Set ConstraintA -> Set Text
forall b a. Ord b => (a -> b) -> Set a -> Set b
S.map (Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text)
-> (ConstraintA -> Doc Any) -> ConstraintA -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constraint -> Doc Any
forall ann. Constraint -> Doc ann
ppConstraint (Constraint -> Doc Any)
-> (ConstraintA -> Constraint) -> ConstraintA -> Doc Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConstraintA -> Constraint
forall a b. (a, b) -> a
fst)

ppShowCAs :: Show (f Text) => Functor f => f ConstraintA -> Text
ppShowCAs :: forall (f :: * -> *).
(Show (f Text), Functor f) =>
f ConstraintA -> Text
ppShowCAs = f Text -> Text
forall a. Show a => a -> Text
pShow (f Text -> Text)
-> (f ConstraintA -> f Text) -> f ConstraintA -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ConstraintA -> Text) -> f ConstraintA -> f Text
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text)
-> (ConstraintA -> Doc Any) -> ConstraintA -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constraint -> Doc Any
forall ann. Constraint -> Doc ann
ppConstraint (Constraint -> Doc Any)
-> (ConstraintA -> Constraint) -> ConstraintA -> Doc Any
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ConstraintA -> Constraint
forall a b. (a, b) -> a
fst)

printAnn :: Ann -> Text
printAnn :: Ann -> Text
printAnn = Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text) -> (Ann -> Doc Any) -> Ann -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Ann -> Doc Any
forall a ann. Pretty a => a -> Doc ann
pretty

ppAnn :: Ann -> Doc ann
ppAnn :: forall ann. Ann -> Doc ann
ppAnn (Ann SourcePos
src Type
typ) = [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
braced' [SourcePos -> Doc ann
forall ann. SourcePos -> Doc ann
ppSourcePos SourcePos
src, Type -> Doc ann
forall ann. Type -> Doc ann
ppType Type
typ]

ppConstraint :: Constraint -> Doc ann
ppConstraint :: forall ann. Constraint -> Doc ann
ppConstraint = \case
  Equality Type
t1 Type
t2 -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
align (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ Type -> Doc ann
forall ann. Type -> Doc ann
ppType Type
t1 Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"~" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Type -> Doc ann
forall ann. Type -> Doc ann
ppType Type
t2

instance Pretty Parser.SourcePos where
  pretty :: forall ann. SourcePos -> Doc ann
pretty = SourcePos -> Doc ann
forall ann. SourcePos -> Doc ann
ppSourcePos
instance Pretty Ann where
  pretty :: forall ann. Ann -> Doc ann
pretty = Ann -> Doc ann
forall ann. Ann -> Doc ann
ppAnn
instance Pretty Type where
  pretty :: forall ann. Type -> Doc ann
pretty = Type -> Doc ann
forall ann. Type -> Doc ann
ppType
instance Pretty Constraint where
  pretty :: forall ann. Constraint -> Doc ann
pretty = Constraint -> Doc ann
forall ann. Constraint -> Doc ann
ppConstraint

ppTypeError :: TypeErrorA -> Text
ppTypeError :: TypeErrorA -> Text
ppTypeError ([SourcePos]
srcs, TypeError
typeErr) =
  [Text] -> Text
T.unlines
    [ Text
"*** Error from: " Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text -> [Text] -> Text
T.intercalate Text
", and " ((SourcePos -> Text) -> [SourcePos] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map (Doc Any -> Text
forall a. Doc a -> Text
render (Doc Any -> Text) -> (SourcePos -> Doc Any) -> SourcePos -> Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SourcePos -> Doc Any
forall ann. SourcePos -> Doc ann
ppSourcePos) [SourcePos]
srcs)
    , TypeError -> Text
forall a. Show a => a -> Text
pShow TypeError
typeErr
    ]