-- |
-- Module      :  Cryptol.Parser.AST
-- Copyright   :  (c) 2013-2016 Galois, Inc.
-- License     :  BSD3
-- Maintainer  :  cryptol@galois.com
-- Stability   :  provisional
-- Portability :  portable

{-# LANGUAGE Safe #-}

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE FlexibleInstances #-}
module Cryptol.Parser.AST
  ( -- * Names
    Ident, mkIdent, mkInfix, isInfixIdent, nullIdent, identText
  , ModName, modRange
  , PName(..), getModName, getIdent, mkUnqual, mkQual
  , Named(..)
  , Pass(..)
  , Assoc(..)

    -- * Types
  , Schema(..)
  , TParam(..)
  , Kind(..)
  , Type(..)
  , Prop(..)
  , tsName
  , psName
  , tsFixity
  , psFixity

    -- * Declarations
  , Module
  , ModuleG(..)
  , mDecls        -- XXX: Temporary

  , mImports
  , mModParams
  , mIsFunctor
  , isParamDecl

  , ModuleDefinition(..)
  , ModuleInstanceArgs(..)
  , ModuleInstanceNamedArg(..)
  , ModuleInstanceArg(..)
  , ModuleInstance
  , emptyModuleInstance

  , Program(..)
  , TopDecl(..)
  , Decl(..)
  , Fixity(..), defaultFixity
  , FixityCmp(..), compareFixity
  , TySyn(..)
  , PropSyn(..)
  , Bind(..)
  , BindDef(..), LBindDef
  , Pragma(..)
  , ExportType(..)
  , TopLevel(..)
  , Import, ImportG(..), ImportSpec(..), ImpName(..)
  , Newtype(..)
  , PrimType(..)
  , ParameterType(..)
  , ParameterFun(..)
  , NestedModule(..)
  , Signature(..)
  , SigDecl(..)
  , ModParam(..)
  , ParamDecl(..)
  , PropGuardCase(..)

    -- * Interactive
  , ReplInput(..)

    -- * Expressions
  , Expr(..)
  , Literal(..), NumInfo(..), FracInfo(..)
  , Match(..)
  , Pattern(..)
  , Selector(..)
  , TypeInst(..)
  , UpdField(..)
  , UpdHow(..)
  , FunDesc(..)
  , emptyFunDesc
  , PrefixOp(..)
  , prefixFixity
  , asEApps

    -- * Positions
  , Located(..)
  , LPName, LString, LIdent
  , NoPos(..)

    -- * Pretty-printing
  , cppKind, ppSelector
  ) where

import Cryptol.Parser.Name
import Cryptol.Parser.Position
import Cryptol.Parser.Selector
import Cryptol.Utils.Fixity
import Cryptol.Utils.Ident
import Cryptol.Utils.RecordMap
import Cryptol.Utils.PP

import           Data.Map(Map)
import qualified Data.Map as Map
import           Data.List(intersperse)
import           Data.Bits(shiftR)
import           Data.Maybe (catMaybes,mapMaybe)
import           Data.Ratio(numerator,denominator)
import           Data.Text (Text)
import           Numeric(showIntAtBase,showFloat,showHFloat)

import GHC.Generics (Generic)
import Control.DeepSeq

import Prelude ()
import Prelude.Compat

-- AST -------------------------------------------------------------------------

-- | A name with location information.
type LPName    = Located PName

-- | An identifier with location information.
type LIdent    = Located Ident

-- | A string with location information.
type LString  = Located String

-- | A record with located ident fields
type Rec e = RecordMap Ident (Range, e)

newtype Program name = Program [TopDecl name]
                       deriving (Int -> Program name -> ShowS
forall name. Show name => Int -> Program name -> ShowS
forall name. Show name => [Program name] -> ShowS
forall name. Show name => Program name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Program name] -> ShowS
$cshowList :: forall name. Show name => [Program name] -> ShowS
show :: Program name -> FilePath
$cshow :: forall name. Show name => Program name -> FilePath
showsPrec :: Int -> Program name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Program name -> ShowS
Show)

{- | A module for the pre-typechecker phasese. The two parameters are:

  * @mname@ the type of module names. This is because top-level and nested
    modules use differnt types to identify a module.

  * @name@ the type of identifiers used by declarations.
    In the parser this starts off as `PName` and after resolving names
    in the renamer, this becomes `Name`.
-}
data ModuleG mname name = Module
  { forall mname name. ModuleG mname name -> Located mname
mName     :: Located mname              -- ^ Name of the module
  , forall mname name. ModuleG mname name -> ModuleDefinition name
mDef      :: ModuleDefinition name
  } deriving (Int -> ModuleG mname name -> ShowS
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
forall mname name.
(Show mname, Show name) =>
Int -> ModuleG mname name -> ShowS
forall mname name.
(Show mname, Show name) =>
[ModuleG mname name] -> ShowS
forall mname name.
(Show mname, Show name) =>
ModuleG mname name -> FilePath
showList :: [ModuleG mname name] -> ShowS
$cshowList :: forall mname name.
(Show mname, Show name) =>
[ModuleG mname name] -> ShowS
show :: ModuleG mname name -> FilePath
$cshow :: forall mname name.
(Show mname, Show name) =>
ModuleG mname name -> FilePath
showsPrec :: Int -> ModuleG mname name -> ShowS
$cshowsPrec :: forall mname name.
(Show mname, Show name) =>
Int -> ModuleG mname name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall mname name x.
Rep (ModuleG mname name) x -> ModuleG mname name
forall mname name x.
ModuleG mname name -> Rep (ModuleG mname name) x
$cto :: forall mname name x.
Rep (ModuleG mname name) x -> ModuleG mname name
$cfrom :: forall mname name x.
ModuleG mname name -> Rep (ModuleG mname name) x
Generic, forall a. (a -> ()) -> NFData a
forall mname name.
(NFData mname, NFData name) =>
ModuleG mname name -> ()
rnf :: ModuleG mname name -> ()
$crnf :: forall mname name.
(NFData mname, NFData name) =>
ModuleG mname name -> ()
NFData)


-- | Different flavours of module we have.
data ModuleDefinition name =
    NormalModule [TopDecl name]

  | FunctorInstance (Located (ImpName name))
                    (ModuleInstanceArgs name)
                    (ModuleInstance name)
    -- ^ The instance is filled in by the renamer

  | InterfaceModule (Signature name)
    deriving (Int -> ModuleDefinition name -> ShowS
forall name. Show name => Int -> ModuleDefinition name -> ShowS
forall name. Show name => [ModuleDefinition name] -> ShowS
forall name. Show name => ModuleDefinition name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ModuleDefinition name] -> ShowS
$cshowList :: forall name. Show name => [ModuleDefinition name] -> ShowS
show :: ModuleDefinition name -> FilePath
$cshow :: forall name. Show name => ModuleDefinition name -> FilePath
showsPrec :: Int -> ModuleDefinition name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ModuleDefinition name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x.
Rep (ModuleDefinition name) x -> ModuleDefinition name
forall name x.
ModuleDefinition name -> Rep (ModuleDefinition name) x
$cto :: forall name x.
Rep (ModuleDefinition name) x -> ModuleDefinition name
$cfrom :: forall name x.
ModuleDefinition name -> Rep (ModuleDefinition name) x
Generic, forall name. NFData name => ModuleDefinition name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ModuleDefinition name -> ()
$crnf :: forall name. NFData name => ModuleDefinition name -> ()
NFData)

{- | Maps names in the original functor with names in the instnace.
Does *NOT* include the parameters, just names for the definitions.
This *DOES* include entrirs for all the name in the instantiated functor,
including names in modules nested inside the functor. -}
type ModuleInstance name = Map name name

emptyModuleInstance :: Ord name => ModuleInstance name
emptyModuleInstance :: forall name. Ord name => ModuleInstance name
emptyModuleInstance = forall a. Monoid a => a
mempty


-- XXX: Review all places this is used, that it actually makes sense
-- Probably shouldn't exist
mDecls :: ModuleG mname name -> [TopDecl name]
mDecls :: forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m =
  case forall mname name. ModuleG mname name -> ModuleDefinition name
mDef ModuleG mname name
m of
    NormalModule [TopDecl name]
ds         -> [TopDecl name]
ds
    FunctorInstance Located (ImpName name)
_ ModuleInstanceArgs name
_ ModuleInstance name
_   -> []
    InterfaceModule {}      -> []

-- | Imports of top-level (i.e. "file" based) modules.
mImports :: ModuleG mname name -> [ Located Import ]
mImports :: forall mname name. ModuleG mname name -> [Located Import]
mImports ModuleG mname name
m =
  case forall mname name. ModuleG mname name -> ModuleDefinition name
mDef ModuleG mname name
m of
    NormalModule [TopDecl name]
ds     -> forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe forall {name}.
Located (ImportG (ImpName name)) -> Maybe (Located Import)
topImp [ Located (ImportG (ImpName name))
li | DImport Located (ImportG (ImpName name))
li <- [TopDecl name]
ds ]
    FunctorInstance {}  -> []
    InterfaceModule Signature name
sig -> forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe forall {name}.
Located (ImportG (ImpName name)) -> Maybe (Located Import)
topImp (forall name. Signature name -> [Located (ImportG (ImpName name))]
sigImports Signature name
sig)
  where
  topImp :: Located (ImportG (ImpName name)) -> Maybe (Located Import)
topImp Located (ImportG (ImpName name))
li = case forall mname. ImportG mname -> mname
iModule ImportG (ImpName name)
i of
               ImpTop ModName
n -> forall a. a -> Maybe a
Just Located (ImportG (ImpName name))
li { thing :: Import
thing = ImportG (ImpName name)
i { iModule :: ModName
iModule = ModName
n } }
               ImpName name
_        -> forall a. Maybe a
Nothing
    where i :: ImportG (ImpName name)
i = forall a. Located a -> a
thing Located (ImportG (ImpName name))
li


-- | Get the module parameters of a module (new module system)
mModParams :: ModuleG mname name -> [ ModParam name ]
mModParams :: forall mname name. ModuleG mname name -> [ModParam name]
mModParams ModuleG mname name
m = [ ModParam name
p | DModParam ModParam name
p <- forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m ]

mIsFunctor :: ModuleG mname nmae -> Bool
mIsFunctor :: forall mname nmae. ModuleG mname nmae -> Bool
mIsFunctor ModuleG mname nmae
m = forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any forall a. TopDecl a -> Bool
isParamDecl (forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname nmae
m)

isParamDecl :: TopDecl a -> Bool
isParamDecl :: forall a. TopDecl a -> Bool
isParamDecl TopDecl a
d =
  case TopDecl a
d of
    DModParam {} -> Bool
True
    DParamDecl {} -> Bool
True
    TopDecl a
_ -> Bool
False


-- | A top-level module
type Module = ModuleG ModName

-- | A nested module.
newtype NestedModule name = NestedModule (ModuleG name name)
  deriving (Int -> NestedModule name -> ShowS
forall name. Show name => Int -> NestedModule name -> ShowS
forall name. Show name => [NestedModule name] -> ShowS
forall name. Show name => NestedModule name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [NestedModule name] -> ShowS
$cshowList :: forall name. Show name => [NestedModule name] -> ShowS
show :: NestedModule name -> FilePath
$cshow :: forall name. Show name => NestedModule name -> FilePath
showsPrec :: Int -> NestedModule name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> NestedModule name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (NestedModule name) x -> NestedModule name
forall name x. NestedModule name -> Rep (NestedModule name) x
$cto :: forall name x. Rep (NestedModule name) x -> NestedModule name
$cfrom :: forall name x. NestedModule name -> Rep (NestedModule name) x
Generic,forall name. NFData name => NestedModule name -> ()
forall a. (a -> ()) -> NFData a
rnf :: NestedModule name -> ()
$crnf :: forall name. NFData name => NestedModule name -> ()
NFData)


modRange :: Module name -> Range
modRange :: forall name. Module name -> Range
modRange Module name
m = [Range] -> Range
rCombs forall a b. (a -> b) -> a -> b
$ forall a. [Maybe a] -> [a]
catMaybes
    [ forall t. HasLoc t => t -> Maybe Range
getLoc (forall mname name. ModuleG mname name -> Located mname
mName Module name
m)
    , forall t. HasLoc t => t -> Maybe Range
getLoc (forall mname name. ModuleG mname name -> [Located Import]
mImports Module name
m)
    , forall t. HasLoc t => t -> Maybe Range
getLoc (forall mname name. ModuleG mname name -> [TopDecl name]
mDecls Module name
m)
    , forall a. a -> Maybe a
Just (Range { from :: Position
from = Position
start, to :: Position
to = Position
start, source :: FilePath
source = FilePath
"" })
    ]

-- | A declaration that may only appear at the top level of a module.
-- The module may be nested, however.
data TopDecl name =
    Decl (TopLevel (Decl name))
  | DPrimType (TopLevel (PrimType name))
  | TDNewtype (TopLevel (Newtype name)) -- ^ @newtype T as = t
  | Include (Located FilePath)          -- ^ @include File@ (until NoInclude)

  | DParamDecl Range (Signature name)   -- ^ @parameter ...@ (parser only)

  | DModule (TopLevel (NestedModule name))      -- ^ @submodule M where ...@
  | DImport (Located (ImportG (ImpName name)))  -- ^ @import X@
  | DModParam (ModParam name)                   -- ^ @import interface X ...@
  | DInterfaceConstraint (Maybe Text) (Located [Prop name])
    -- ^ @interface constraint@
    deriving (Int -> TopDecl name -> ShowS
forall name. Show name => Int -> TopDecl name -> ShowS
forall name. Show name => [TopDecl name] -> ShowS
forall name. Show name => TopDecl name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [TopDecl name] -> ShowS
$cshowList :: forall name. Show name => [TopDecl name] -> ShowS
show :: TopDecl name -> FilePath
$cshow :: forall name. Show name => TopDecl name -> FilePath
showsPrec :: Int -> TopDecl name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> TopDecl name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (TopDecl name) x -> TopDecl name
forall name x. TopDecl name -> Rep (TopDecl name) x
$cto :: forall name x. Rep (TopDecl name) x -> TopDecl name
$cfrom :: forall name x. TopDecl name -> Rep (TopDecl name) x
Generic, forall name. NFData name => TopDecl name -> ()
forall a. (a -> ()) -> NFData a
rnf :: TopDecl name -> ()
$crnf :: forall name. NFData name => TopDecl name -> ()
NFData)


-- | Things that maybe appear in an interface/parameter block.
-- These only exist during parsering.
data ParamDecl name =

    DParameterType (ParameterType name) -- ^ @parameter type T : #@ (parser only)
  | DParameterFun  (ParameterFun name)  -- ^ @parameter someVal : [256]@
                                        -- (parser only)

  | DParameterDecl (SigDecl name)       -- ^ A delcaration in an interface

  | DParameterConstraint [Located (Prop name)]
    -- ^ @parameter type constraint (fin T)@

    deriving (Int -> ParamDecl name -> ShowS
forall name. Show name => Int -> ParamDecl name -> ShowS
forall name. Show name => [ParamDecl name] -> ShowS
forall name. Show name => ParamDecl name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ParamDecl name] -> ShowS
$cshowList :: forall name. Show name => [ParamDecl name] -> ShowS
show :: ParamDecl name -> FilePath
$cshow :: forall name. Show name => ParamDecl name -> FilePath
showsPrec :: Int -> ParamDecl name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ParamDecl name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (ParamDecl name) x -> ParamDecl name
forall name x. ParamDecl name -> Rep (ParamDecl name) x
$cto :: forall name x. Rep (ParamDecl name) x -> ParamDecl name
$cfrom :: forall name x. ParamDecl name -> Rep (ParamDecl name) x
Generic, forall name. NFData name => ParamDecl name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ParamDecl name -> ()
$crnf :: forall name. NFData name => ParamDecl name -> ()
NFData)


-- | All arguments in a functor instantiation
data ModuleInstanceArgs name =
    DefaultInstArg (Located (ModuleInstanceArg name))
    -- ^ Single parameter instantitaion

  | DefaultInstAnonArg [TopDecl name]
    -- ^ Single parameter instantitaion using this anonymous module.
    -- (parser only)

  | NamedInstArgs  [ModuleInstanceNamedArg name]

    deriving (Int -> ModuleInstanceArgs name -> ShowS
forall name. Show name => Int -> ModuleInstanceArgs name -> ShowS
forall name. Show name => [ModuleInstanceArgs name] -> ShowS
forall name. Show name => ModuleInstanceArgs name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ModuleInstanceArgs name] -> ShowS
$cshowList :: forall name. Show name => [ModuleInstanceArgs name] -> ShowS
show :: ModuleInstanceArgs name -> FilePath
$cshow :: forall name. Show name => ModuleInstanceArgs name -> FilePath
showsPrec :: Int -> ModuleInstanceArgs name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ModuleInstanceArgs name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x.
Rep (ModuleInstanceArgs name) x -> ModuleInstanceArgs name
forall name x.
ModuleInstanceArgs name -> Rep (ModuleInstanceArgs name) x
$cto :: forall name x.
Rep (ModuleInstanceArgs name) x -> ModuleInstanceArgs name
$cfrom :: forall name x.
ModuleInstanceArgs name -> Rep (ModuleInstanceArgs name) x
Generic, forall name. NFData name => ModuleInstanceArgs name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ModuleInstanceArgs name -> ()
$crnf :: forall name. NFData name => ModuleInstanceArgs name -> ()
NFData)

-- | A named argument in a functor instantiation
data ModuleInstanceNamedArg name =
  ModuleInstanceNamedArg (Located Ident) (Located (ModuleInstanceArg name))
  deriving (Int -> ModuleInstanceNamedArg name -> ShowS
forall name.
Show name =>
Int -> ModuleInstanceNamedArg name -> ShowS
forall name. Show name => [ModuleInstanceNamedArg name] -> ShowS
forall name. Show name => ModuleInstanceNamedArg name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ModuleInstanceNamedArg name] -> ShowS
$cshowList :: forall name. Show name => [ModuleInstanceNamedArg name] -> ShowS
show :: ModuleInstanceNamedArg name -> FilePath
$cshow :: forall name. Show name => ModuleInstanceNamedArg name -> FilePath
showsPrec :: Int -> ModuleInstanceNamedArg name -> ShowS
$cshowsPrec :: forall name.
Show name =>
Int -> ModuleInstanceNamedArg name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x.
Rep (ModuleInstanceNamedArg name) x -> ModuleInstanceNamedArg name
forall name x.
ModuleInstanceNamedArg name -> Rep (ModuleInstanceNamedArg name) x
$cto :: forall name x.
Rep (ModuleInstanceNamedArg name) x -> ModuleInstanceNamedArg name
$cfrom :: forall name x.
ModuleInstanceNamedArg name -> Rep (ModuleInstanceNamedArg name) x
Generic, forall name. NFData name => ModuleInstanceNamedArg name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ModuleInstanceNamedArg name -> ()
$crnf :: forall name. NFData name => ModuleInstanceNamedArg name -> ()
NFData)

-- | An argument in a functor instantiation
data ModuleInstanceArg name =
    ModuleArg (ImpName name)  -- ^ An argument that is a module
  | ParameterArg Ident        -- ^ An argument that is a parameter
  | AddParams                 -- ^ Arguments adds extra parameters to decls.
                              -- ("backtick" import)
    deriving (Int -> ModuleInstanceArg name -> ShowS
forall name. Show name => Int -> ModuleInstanceArg name -> ShowS
forall name. Show name => [ModuleInstanceArg name] -> ShowS
forall name. Show name => ModuleInstanceArg name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ModuleInstanceArg name] -> ShowS
$cshowList :: forall name. Show name => [ModuleInstanceArg name] -> ShowS
show :: ModuleInstanceArg name -> FilePath
$cshow :: forall name. Show name => ModuleInstanceArg name -> FilePath
showsPrec :: Int -> ModuleInstanceArg name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ModuleInstanceArg name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x.
Rep (ModuleInstanceArg name) x -> ModuleInstanceArg name
forall name x.
ModuleInstanceArg name -> Rep (ModuleInstanceArg name) x
$cto :: forall name x.
Rep (ModuleInstanceArg name) x -> ModuleInstanceArg name
$cfrom :: forall name x.
ModuleInstanceArg name -> Rep (ModuleInstanceArg name) x
Generic, forall name. NFData name => ModuleInstanceArg name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ModuleInstanceArg name -> ()
$crnf :: forall name. NFData name => ModuleInstanceArg name -> ()
NFData)


-- | The name of an imported module
data ImpName name =
    ImpTop    ModName           -- ^ A top-level module
  | ImpNested name              -- ^ The module in scope with the given name
    deriving (Int -> ImpName name -> ShowS
forall name. Show name => Int -> ImpName name -> ShowS
forall name. Show name => [ImpName name] -> ShowS
forall name. Show name => ImpName name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ImpName name] -> ShowS
$cshowList :: forall name. Show name => [ImpName name] -> ShowS
show :: ImpName name -> FilePath
$cshow :: forall name. Show name => ImpName name -> FilePath
showsPrec :: Int -> ImpName name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ImpName name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (ImpName name) x -> ImpName name
forall name x. ImpName name -> Rep (ImpName name) x
$cto :: forall name x. Rep (ImpName name) x -> ImpName name
$cfrom :: forall name x. ImpName name -> Rep (ImpName name) x
Generic, forall name. NFData name => ImpName name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ImpName name -> ()
$crnf :: forall name. NFData name => ImpName name -> ()
NFData, ImpName name -> ImpName name -> Bool
forall name. Eq name => ImpName name -> ImpName name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImpName name -> ImpName name -> Bool
$c/= :: forall name. Eq name => ImpName name -> ImpName name -> Bool
== :: ImpName name -> ImpName name -> Bool
$c== :: forall name. Eq name => ImpName name -> ImpName name -> Bool
Eq, ImpName name -> ImpName name -> Bool
ImpName name -> ImpName name -> Ordering
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 {name}. Ord name => Eq (ImpName name)
forall name. Ord name => ImpName name -> ImpName name -> Bool
forall name. Ord name => ImpName name -> ImpName name -> Ordering
forall name.
Ord name =>
ImpName name -> ImpName name -> ImpName name
min :: ImpName name -> ImpName name -> ImpName name
$cmin :: forall name.
Ord name =>
ImpName name -> ImpName name -> ImpName name
max :: ImpName name -> ImpName name -> ImpName name
$cmax :: forall name.
Ord name =>
ImpName name -> ImpName name -> ImpName name
>= :: ImpName name -> ImpName name -> Bool
$c>= :: forall name. Ord name => ImpName name -> ImpName name -> Bool
> :: ImpName name -> ImpName name -> Bool
$c> :: forall name. Ord name => ImpName name -> ImpName name -> Bool
<= :: ImpName name -> ImpName name -> Bool
$c<= :: forall name. Ord name => ImpName name -> ImpName name -> Bool
< :: ImpName name -> ImpName name -> Bool
$c< :: forall name. Ord name => ImpName name -> ImpName name -> Bool
compare :: ImpName name -> ImpName name -> Ordering
$ccompare :: forall name. Ord name => ImpName name -> ImpName name -> Ordering
Ord)

-- | A simple declaration.  Generally these are things that can appear
-- both at the top-level of a module and in `where` clauses.
data Decl name = DSignature [Located name] (Schema name)
                 -- ^ A type signature.  Eliminated in NoPat--after NoPat
                 -- signatures are in their associated Bind

               | DFixity !Fixity [Located name]
                 -- ^ A fixity declaration. Eliminated in NoPat---after NoPat
                 -- fixities are in their associated Bind

               | DPragma [Located name] Pragma
                 -- ^ A pragma declaration. Eliminated in NoPat---after NoPat
                 -- fixities are in their associated Bind

               | DBind (Bind name)
                -- ^ A non-recursive binding.

               | DRec [Bind name]
                 -- ^ A group of recursive bindings. Introduced by the renamer.

               | DPatBind (Pattern name) (Expr name)
                 -- ^ A pattern binding. Eliminated in NoPat---after NoPat
                 -- fixities are in their associated Bind

               | DType (TySyn name)
                 -- ^ A type synonym.

               | DProp (PropSyn name)
                 -- ^ A constraint synonym.

               | DLocated (Decl name) Range
                 -- ^ Keeps track of the location of a declaration.

                 deriving (Decl name -> Decl name -> Bool
forall name. Eq name => Decl name -> Decl name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Decl name -> Decl name -> Bool
$c/= :: forall name. Eq name => Decl name -> Decl name -> Bool
== :: Decl name -> Decl name -> Bool
$c== :: forall name. Eq name => Decl name -> Decl name -> Bool
Eq, Int -> Decl name -> ShowS
forall name. Show name => Int -> Decl name -> ShowS
forall name. Show name => [Decl name] -> ShowS
forall name. Show name => Decl name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Decl name] -> ShowS
$cshowList :: forall name. Show name => [Decl name] -> ShowS
show :: Decl name -> FilePath
$cshow :: forall name. Show name => Decl name -> FilePath
showsPrec :: Int -> Decl name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Decl name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (Decl name) x -> Decl name
forall name x. Decl name -> Rep (Decl name) x
$cto :: forall name x. Rep (Decl name) x -> Decl name
$cfrom :: forall name x. Decl name -> Rep (Decl name) x
Generic, forall name. NFData name => Decl name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Decl name -> ()
$crnf :: forall name. NFData name => Decl name -> ()
NFData, forall a b. a -> Decl b -> Decl a
forall a b. (a -> b) -> Decl a -> Decl b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Decl b -> Decl a
$c<$ :: forall a b. a -> Decl b -> Decl a
fmap :: forall a b. (a -> b) -> Decl a -> Decl b
$cfmap :: forall a b. (a -> b) -> Decl a -> Decl b
Functor)


-- | A type parameter for a module.
data ParameterType name = ParameterType
  { forall name. ParameterType name -> Located name
ptName    :: Located name     -- ^ name of type parameter
  , forall name. ParameterType name -> Kind
ptKind    :: Kind             -- ^ kind of parameter
  , forall name. ParameterType name -> Maybe Text
ptDoc     :: Maybe Text       -- ^ optional documentation
  , forall name. ParameterType name -> Maybe Fixity
ptFixity  :: Maybe Fixity     -- ^ info for infix use
  , forall name. ParameterType name -> Int
ptNumber  :: !Int             -- ^ number of the parameter
  } deriving (ParameterType name -> ParameterType name -> Bool
forall name.
Eq name =>
ParameterType name -> ParameterType name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParameterType name -> ParameterType name -> Bool
$c/= :: forall name.
Eq name =>
ParameterType name -> ParameterType name -> Bool
== :: ParameterType name -> ParameterType name -> Bool
$c== :: forall name.
Eq name =>
ParameterType name -> ParameterType name -> Bool
Eq,Int -> ParameterType name -> ShowS
forall name. Show name => Int -> ParameterType name -> ShowS
forall name. Show name => [ParameterType name] -> ShowS
forall name. Show name => ParameterType name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ParameterType name] -> ShowS
$cshowList :: forall name. Show name => [ParameterType name] -> ShowS
show :: ParameterType name -> FilePath
$cshow :: forall name. Show name => ParameterType name -> FilePath
showsPrec :: Int -> ParameterType name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ParameterType name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (ParameterType name) x -> ParameterType name
forall name x. ParameterType name -> Rep (ParameterType name) x
$cto :: forall name x. Rep (ParameterType name) x -> ParameterType name
$cfrom :: forall name x. ParameterType name -> Rep (ParameterType name) x
Generic,forall name. NFData name => ParameterType name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ParameterType name -> ()
$crnf :: forall name. NFData name => ParameterType name -> ()
NFData)

-- | A value parameter for a module.
data ParameterFun name = ParameterFun
  { forall name. ParameterFun name -> Located name
pfName   :: Located name      -- ^ name of value parameter
  , forall name. ParameterFun name -> Schema name
pfSchema :: Schema name       -- ^ schema for parameter
  , forall name. ParameterFun name -> Maybe Text
pfDoc    :: Maybe Text        -- ^ optional documentation
  , forall name. ParameterFun name -> Maybe Fixity
pfFixity :: Maybe Fixity      -- ^ info for infix use
  } deriving (ParameterFun name -> ParameterFun name -> Bool
forall name.
Eq name =>
ParameterFun name -> ParameterFun name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ParameterFun name -> ParameterFun name -> Bool
$c/= :: forall name.
Eq name =>
ParameterFun name -> ParameterFun name -> Bool
== :: ParameterFun name -> ParameterFun name -> Bool
$c== :: forall name.
Eq name =>
ParameterFun name -> ParameterFun name -> Bool
Eq,Int -> ParameterFun name -> ShowS
forall name. Show name => Int -> ParameterFun name -> ShowS
forall name. Show name => [ParameterFun name] -> ShowS
forall name. Show name => ParameterFun name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ParameterFun name] -> ShowS
$cshowList :: forall name. Show name => [ParameterFun name] -> ShowS
show :: ParameterFun name -> FilePath
$cshow :: forall name. Show name => ParameterFun name -> FilePath
showsPrec :: Int -> ParameterFun name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ParameterFun name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (ParameterFun name) x -> ParameterFun name
forall name x. ParameterFun name -> Rep (ParameterFun name) x
$cto :: forall name x. Rep (ParameterFun name) x -> ParameterFun name
$cfrom :: forall name x. ParameterFun name -> Rep (ParameterFun name) x
Generic,forall name. NFData name => ParameterFun name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ParameterFun name -> ()
$crnf :: forall name. NFData name => ParameterFun name -> ()
NFData)


{- | Interface Modules (aka types of functor arguments)

IMPORTANT: Interface Modules are a language construct and are different from
the notion of "interface" in the Cryptol implementation.

Note that the names *defined* in an interface module are only really used in the
other members of the interface module.  When an interface module  is "imported"
as a functor parameter these names are instantiated to new names,
because there could be multiple paramers using the same interface. -}
data Signature name = Signature
  { forall name. Signature name -> [Located (ImportG (ImpName name))]
sigImports      :: ![Located (ImportG (ImpName name))]
    -- ^ Add things in scope
  , forall name. Signature name -> [ParameterType name]
sigTypeParams   :: [ParameterType name]     -- ^ Type parameters
  , forall name. Signature name -> [Located (Prop name)]
sigConstraints  :: [Located (Prop name)]
    -- ^ Constraints on the type parameters and type synonyms.
  , forall name. Signature name -> [SigDecl name]
sigDecls        :: [SigDecl name]
    -- ^ Type and constraint synonyms
  , forall name. Signature name -> [ParameterFun name]
sigFunParams    :: [ParameterFun name]      -- ^ Value parameters
  } deriving (Int -> Signature name -> ShowS
forall name. Show name => Int -> Signature name -> ShowS
forall name. Show name => [Signature name] -> ShowS
forall name. Show name => Signature name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Signature name] -> ShowS
$cshowList :: forall name. Show name => [Signature name] -> ShowS
show :: Signature name -> FilePath
$cshow :: forall name. Show name => Signature name -> FilePath
showsPrec :: Int -> Signature name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Signature name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (Signature name) x -> Signature name
forall name x. Signature name -> Rep (Signature name) x
$cto :: forall name x. Rep (Signature name) x -> Signature name
$cfrom :: forall name x. Signature name -> Rep (Signature name) x
Generic,forall name. NFData name => Signature name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Signature name -> ()
$crnf :: forall name. NFData name => Signature name -> ()
NFData)

-- | A constraint or type synonym declared in an interface.
data SigDecl name =
    SigTySyn (TySyn name) (Maybe Text)
  | SigPropSyn (PropSyn name) (Maybe Text)
    deriving (Int -> SigDecl name -> ShowS
forall name. Show name => Int -> SigDecl name -> ShowS
forall name. Show name => [SigDecl name] -> ShowS
forall name. Show name => SigDecl name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [SigDecl name] -> ShowS
$cshowList :: forall name. Show name => [SigDecl name] -> ShowS
show :: SigDecl name -> FilePath
$cshow :: forall name. Show name => SigDecl name -> FilePath
showsPrec :: Int -> SigDecl name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> SigDecl name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (SigDecl name) x -> SigDecl name
forall name x. SigDecl name -> Rep (SigDecl name) x
$cto :: forall name x. Rep (SigDecl name) x -> SigDecl name
$cfrom :: forall name x. SigDecl name -> Rep (SigDecl name) x
Generic,forall name. NFData name => SigDecl name -> ()
forall a. (a -> ()) -> NFData a
rnf :: SigDecl name -> ()
$crnf :: forall name. NFData name => SigDecl name -> ()
NFData)

{- | A module parameter declaration.

> import interface A
> import interface A as B

The name of the parameter is derived from the `as` clause.  If there
is no `as` clause then it is derived from the name of the interface module.

If there is no `as` clause, then the type/value parameters are unqualified,
and otherwise they are qualified.
-}
data ModParam name = ModParam
  { forall name. ModParam name -> Located (ImpName name)
mpSignature     :: Located (ImpName name)  -- ^ Signature for parameter
  , forall name. ModParam name -> Maybe ModName
mpAs            :: Maybe ModName        -- ^ Qualified for actual params
  , forall name. ModParam name -> Ident
mpName          :: !Ident
    {- ^ Parameter name (for inst.)
    Note that this is not resolved in the renamer, and is only used
    when instantiating a functor. -}

  , forall name. ModParam name -> Maybe (Located Text)
mpDoc           :: Maybe (Located Text) -- ^ Optional documentation
  , forall name. ModParam name -> Map name name
mpRenaming      :: !(Map name name)
    {- ^ Filled in by the renamer.
      Maps the actual (value/type) parameter names to the names in the
      interface module. -}
  } deriving (ModParam name -> ModParam name -> Bool
forall name. Eq name => ModParam name -> ModParam name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ModParam name -> ModParam name -> Bool
$c/= :: forall name. Eq name => ModParam name -> ModParam name -> Bool
== :: ModParam name -> ModParam name -> Bool
$c== :: forall name. Eq name => ModParam name -> ModParam name -> Bool
Eq,Int -> ModParam name -> ShowS
forall name. Show name => Int -> ModParam name -> ShowS
forall name. Show name => [ModParam name] -> ShowS
forall name. Show name => ModParam name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ModParam name] -> ShowS
$cshowList :: forall name. Show name => [ModParam name] -> ShowS
show :: ModParam name -> FilePath
$cshow :: forall name. Show name => ModParam name -> FilePath
showsPrec :: Int -> ModParam name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ModParam name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (ModParam name) x -> ModParam name
forall name x. ModParam name -> Rep (ModParam name) x
$cto :: forall name x. Rep (ModParam name) x -> ModParam name
$cfrom :: forall name x. ModParam name -> Rep (ModParam name) x
Generic,forall name. NFData name => ModParam name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ModParam name -> ()
$crnf :: forall name. NFData name => ModParam name -> ()
NFData)


-- | An import declaration.
data ImportG mname = Import
  { forall mname. ImportG mname -> mname
iModule    :: !mname
  , forall mname. ImportG mname -> Maybe ModName
iAs        :: Maybe ModName
  , forall mname. ImportG mname -> Maybe ImportSpec
iSpec      :: Maybe ImportSpec
  , forall mname. ImportG mname -> Maybe (ModuleInstanceArgs PName)
iInst      :: !(Maybe (ModuleInstanceArgs PName))
    -- ^ `iInst' exists only during parsing
  } deriving (Int -> ImportG mname -> ShowS
forall mname. Show mname => Int -> ImportG mname -> ShowS
forall mname. Show mname => [ImportG mname] -> ShowS
forall mname. Show mname => ImportG mname -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ImportG mname] -> ShowS
$cshowList :: forall mname. Show mname => [ImportG mname] -> ShowS
show :: ImportG mname -> FilePath
$cshow :: forall mname. Show mname => ImportG mname -> FilePath
showsPrec :: Int -> ImportG mname -> ShowS
$cshowsPrec :: forall mname. Show mname => Int -> ImportG mname -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall mname x. Rep (ImportG mname) x -> ImportG mname
forall mname x. ImportG mname -> Rep (ImportG mname) x
$cto :: forall mname x. Rep (ImportG mname) x -> ImportG mname
$cfrom :: forall mname x. ImportG mname -> Rep (ImportG mname) x
Generic, forall mname. NFData mname => ImportG mname -> ()
forall a. (a -> ()) -> NFData a
rnf :: ImportG mname -> ()
$crnf :: forall mname. NFData mname => ImportG mname -> ()
NFData)

type Import = ImportG ModName

-- | The list of names following an import.
data ImportSpec = Hiding [Ident]
                | Only   [Ident]
                  deriving (ImportSpec -> ImportSpec -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportSpec -> ImportSpec -> Bool
$c/= :: ImportSpec -> ImportSpec -> Bool
== :: ImportSpec -> ImportSpec -> Bool
$c== :: ImportSpec -> ImportSpec -> Bool
Eq, Int -> ImportSpec -> ShowS
[ImportSpec] -> ShowS
ImportSpec -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ImportSpec] -> ShowS
$cshowList :: [ImportSpec] -> ShowS
show :: ImportSpec -> FilePath
$cshow :: ImportSpec -> FilePath
showsPrec :: Int -> ImportSpec -> ShowS
$cshowsPrec :: Int -> ImportSpec -> ShowS
Show, forall x. Rep ImportSpec x -> ImportSpec
forall x. ImportSpec -> Rep ImportSpec x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ImportSpec x -> ImportSpec
$cfrom :: forall x. ImportSpec -> Rep ImportSpec x
Generic, ImportSpec -> ()
forall a. (a -> ()) -> NFData a
rnf :: ImportSpec -> ()
$crnf :: ImportSpec -> ()
NFData)

-- The 'Maybe Fixity' field is filled in by the NoPat pass.
data TySyn n = TySyn (Located n) (Maybe Fixity) [TParam n] (Type n)
                deriving (TySyn n -> TySyn n -> Bool
forall n. Eq n => TySyn n -> TySyn n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TySyn n -> TySyn n -> Bool
$c/= :: forall n. Eq n => TySyn n -> TySyn n -> Bool
== :: TySyn n -> TySyn n -> Bool
$c== :: forall n. Eq n => TySyn n -> TySyn n -> Bool
Eq, Int -> TySyn n -> ShowS
forall n. Show n => Int -> TySyn n -> ShowS
forall n. Show n => [TySyn n] -> ShowS
forall n. Show n => TySyn n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [TySyn n] -> ShowS
$cshowList :: forall n. Show n => [TySyn n] -> ShowS
show :: TySyn n -> FilePath
$cshow :: forall n. Show n => TySyn n -> FilePath
showsPrec :: Int -> TySyn n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> TySyn n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (TySyn n) x -> TySyn n
forall n x. TySyn n -> Rep (TySyn n) x
$cto :: forall n x. Rep (TySyn n) x -> TySyn n
$cfrom :: forall n x. TySyn n -> Rep (TySyn n) x
Generic, forall n. NFData n => TySyn n -> ()
forall a. (a -> ()) -> NFData a
rnf :: TySyn n -> ()
$crnf :: forall n. NFData n => TySyn n -> ()
NFData, forall a b. a -> TySyn b -> TySyn a
forall a b. (a -> b) -> TySyn a -> TySyn b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> TySyn b -> TySyn a
$c<$ :: forall a b. a -> TySyn b -> TySyn a
fmap :: forall a b. (a -> b) -> TySyn a -> TySyn b
$cfmap :: forall a b. (a -> b) -> TySyn a -> TySyn b
Functor)

-- The 'Maybe Fixity' field is filled in by the NoPat pass.
data PropSyn n = PropSyn (Located n) (Maybe Fixity) [TParam n] [Prop n]
                 deriving (PropSyn n -> PropSyn n -> Bool
forall n. Eq n => PropSyn n -> PropSyn n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PropSyn n -> PropSyn n -> Bool
$c/= :: forall n. Eq n => PropSyn n -> PropSyn n -> Bool
== :: PropSyn n -> PropSyn n -> Bool
$c== :: forall n. Eq n => PropSyn n -> PropSyn n -> Bool
Eq, Int -> PropSyn n -> ShowS
forall n. Show n => Int -> PropSyn n -> ShowS
forall n. Show n => [PropSyn n] -> ShowS
forall n. Show n => PropSyn n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PropSyn n] -> ShowS
$cshowList :: forall n. Show n => [PropSyn n] -> ShowS
show :: PropSyn n -> FilePath
$cshow :: forall n. Show n => PropSyn n -> FilePath
showsPrec :: Int -> PropSyn n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> PropSyn n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (PropSyn n) x -> PropSyn n
forall n x. PropSyn n -> Rep (PropSyn n) x
$cto :: forall n x. Rep (PropSyn n) x -> PropSyn n
$cfrom :: forall n x. PropSyn n -> Rep (PropSyn n) x
Generic, forall n. NFData n => PropSyn n -> ()
forall a. (a -> ()) -> NFData a
rnf :: PropSyn n -> ()
$crnf :: forall n. NFData n => PropSyn n -> ()
NFData, forall a b. a -> PropSyn b -> PropSyn a
forall a b. (a -> b) -> PropSyn a -> PropSyn b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PropSyn b -> PropSyn a
$c<$ :: forall a b. a -> PropSyn b -> PropSyn a
fmap :: forall a b. (a -> b) -> PropSyn a -> PropSyn b
$cfmap :: forall a b. (a -> b) -> PropSyn a -> PropSyn b
Functor)

tsName :: TySyn name -> Located name
tsName :: forall name. TySyn name -> Located name
tsName (TySyn Located name
lqn Maybe Fixity
_ [TParam name]
_ Type name
_) = Located name
lqn

psName :: PropSyn name -> Located name
psName :: forall name. PropSyn name -> Located name
psName (PropSyn Located name
lqn Maybe Fixity
_ [TParam name]
_ [Prop name]
_) = Located name
lqn

tsFixity :: TySyn name -> Maybe Fixity
tsFixity :: forall name. TySyn name -> Maybe Fixity
tsFixity (TySyn Located name
_ Maybe Fixity
f [TParam name]
_ Type name
_) = Maybe Fixity
f

psFixity :: PropSyn name -> Maybe Fixity
psFixity :: forall name. PropSyn name -> Maybe Fixity
psFixity (PropSyn Located name
_ Maybe Fixity
f [TParam name]
_ [Prop name]
_) = Maybe Fixity
f

{- | Bindings.  Notes:

    * The parser does not associate type signatures and pragmas with
      their bindings: this is done in a separate pass, after de-sugaring
      pattern bindings.  In this way we can associate pragmas and type
      signatures with the variables defined by pattern bindings as well.

    * Currently, there is no surface syntax for defining monomorphic
      bindings (i.e., bindings that will not be automatically generalized
      by the type checker.  However, they are useful when de-sugaring
      patterns.
-}
data Bind name = Bind
  { forall name. Bind name -> Located name
bName      :: Located name            -- ^ Defined thing
  , forall name. Bind name -> [Pattern name]
bParams    :: [Pattern name]          -- ^ Parameters
  , forall name. Bind name -> Located (BindDef name)
bDef       :: Located (BindDef name)  -- ^ Definition
  , forall name. Bind name -> Maybe (Schema name)
bSignature :: Maybe (Schema name)     -- ^ Optional type sig
  , forall name. Bind name -> Bool
bInfix     :: Bool                    -- ^ Infix operator?
  , forall name. Bind name -> Maybe Fixity
bFixity    :: Maybe Fixity            -- ^ Optional fixity info
  , forall name. Bind name -> [Pragma]
bPragmas   :: [Pragma]                -- ^ Optional pragmas
  , forall name. Bind name -> Bool
bMono      :: Bool                    -- ^ Is this a monomorphic binding
  , forall name. Bind name -> Maybe Text
bDoc       :: Maybe Text              -- ^ Optional doc string
  , forall name. Bind name -> ExportType
bExport    :: !ExportType
  } deriving (Bind name -> Bind name -> Bool
forall name. Eq name => Bind name -> Bind name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Bind name -> Bind name -> Bool
$c/= :: forall name. Eq name => Bind name -> Bind name -> Bool
== :: Bind name -> Bind name -> Bool
$c== :: forall name. Eq name => Bind name -> Bind name -> Bool
Eq, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (Bind name) x -> Bind name
forall name x. Bind name -> Rep (Bind name) x
$cto :: forall name x. Rep (Bind name) x -> Bind name
$cfrom :: forall name x. Bind name -> Rep (Bind name) x
Generic, forall name. NFData name => Bind name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Bind name -> ()
$crnf :: forall name. NFData name => Bind name -> ()
NFData, forall a b. a -> Bind b -> Bind a
forall a b. (a -> b) -> Bind a -> Bind b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Bind b -> Bind a
$c<$ :: forall a b. a -> Bind b -> Bind a
fmap :: forall a b. (a -> b) -> Bind a -> Bind b
$cfmap :: forall a b. (a -> b) -> Bind a -> Bind b
Functor, Int -> Bind name -> ShowS
forall name. Show name => Int -> Bind name -> ShowS
forall name. Show name => [Bind name] -> ShowS
forall name. Show name => Bind name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Bind name] -> ShowS
$cshowList :: forall name. Show name => [Bind name] -> ShowS
show :: Bind name -> FilePath
$cshow :: forall name. Show name => Bind name -> FilePath
showsPrec :: Int -> Bind name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Bind name -> ShowS
Show)

type LBindDef = Located (BindDef PName)

data BindDef name = DPrim
                  | DForeign
                  | DExpr (Expr name)
                  | DPropGuards [PropGuardCase name]
                    deriving (BindDef name -> BindDef name -> Bool
forall name. Eq name => BindDef name -> BindDef name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BindDef name -> BindDef name -> Bool
$c/= :: forall name. Eq name => BindDef name -> BindDef name -> Bool
== :: BindDef name -> BindDef name -> Bool
$c== :: forall name. Eq name => BindDef name -> BindDef name -> Bool
Eq, Int -> BindDef name -> ShowS
forall name. Show name => Int -> BindDef name -> ShowS
forall name. Show name => [BindDef name] -> ShowS
forall name. Show name => BindDef name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [BindDef name] -> ShowS
$cshowList :: forall name. Show name => [BindDef name] -> ShowS
show :: BindDef name -> FilePath
$cshow :: forall name. Show name => BindDef name -> FilePath
showsPrec :: Int -> BindDef name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> BindDef name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (BindDef name) x -> BindDef name
forall name x. BindDef name -> Rep (BindDef name) x
$cto :: forall name x. Rep (BindDef name) x -> BindDef name
$cfrom :: forall name x. BindDef name -> Rep (BindDef name) x
Generic, forall name. NFData name => BindDef name -> ()
forall a. (a -> ()) -> NFData a
rnf :: BindDef name -> ()
$crnf :: forall name. NFData name => BindDef name -> ()
NFData, forall a b. a -> BindDef b -> BindDef a
forall a b. (a -> b) -> BindDef a -> BindDef b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> BindDef b -> BindDef a
$c<$ :: forall a b. a -> BindDef b -> BindDef a
fmap :: forall a b. (a -> b) -> BindDef a -> BindDef b
$cfmap :: forall a b. (a -> b) -> BindDef a -> BindDef b
Functor)

data PropGuardCase name = PropGuardCase
  { forall name. PropGuardCase name -> [Located (Prop name)]
pgcProps :: [Located (Prop name)]
  , forall name. PropGuardCase name -> Expr name
pgcExpr  :: Expr name
  }
  deriving (PropGuardCase name -> PropGuardCase name -> Bool
forall name.
Eq name =>
PropGuardCase name -> PropGuardCase name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PropGuardCase name -> PropGuardCase name -> Bool
$c/= :: forall name.
Eq name =>
PropGuardCase name -> PropGuardCase name -> Bool
== :: PropGuardCase name -> PropGuardCase name -> Bool
$c== :: forall name.
Eq name =>
PropGuardCase name -> PropGuardCase name -> Bool
Eq,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (PropGuardCase name) x -> PropGuardCase name
forall name x. PropGuardCase name -> Rep (PropGuardCase name) x
$cto :: forall name x. Rep (PropGuardCase name) x -> PropGuardCase name
$cfrom :: forall name x. PropGuardCase name -> Rep (PropGuardCase name) x
Generic,forall name. NFData name => PropGuardCase name -> ()
forall a. (a -> ()) -> NFData a
rnf :: PropGuardCase name -> ()
$crnf :: forall name. NFData name => PropGuardCase name -> ()
NFData,forall a b. a -> PropGuardCase b -> PropGuardCase a
forall a b. (a -> b) -> PropGuardCase a -> PropGuardCase b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> PropGuardCase b -> PropGuardCase a
$c<$ :: forall a b. a -> PropGuardCase b -> PropGuardCase a
fmap :: forall a b. (a -> b) -> PropGuardCase a -> PropGuardCase b
$cfmap :: forall a b. (a -> b) -> PropGuardCase a -> PropGuardCase b
Functor,Int -> PropGuardCase name -> ShowS
forall name. Show name => Int -> PropGuardCase name -> ShowS
forall name. Show name => [PropGuardCase name] -> ShowS
forall name. Show name => PropGuardCase name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PropGuardCase name] -> ShowS
$cshowList :: forall name. Show name => [PropGuardCase name] -> ShowS
show :: PropGuardCase name -> FilePath
$cshow :: forall name. Show name => PropGuardCase name -> FilePath
showsPrec :: Int -> PropGuardCase name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> PropGuardCase name -> ShowS
Show)

data Pragma   = PragmaNote String
              | PragmaProperty
                deriving (Pragma -> Pragma -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Pragma -> Pragma -> Bool
$c/= :: Pragma -> Pragma -> Bool
== :: Pragma -> Pragma -> Bool
$c== :: Pragma -> Pragma -> Bool
Eq, Int -> Pragma -> ShowS
[Pragma] -> ShowS
Pragma -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Pragma] -> ShowS
$cshowList :: [Pragma] -> ShowS
show :: Pragma -> FilePath
$cshow :: Pragma -> FilePath
showsPrec :: Int -> Pragma -> ShowS
$cshowsPrec :: Int -> Pragma -> ShowS
Show, forall x. Rep Pragma x -> Pragma
forall x. Pragma -> Rep Pragma x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Pragma x -> Pragma
$cfrom :: forall x. Pragma -> Rep Pragma x
Generic, Pragma -> ()
forall a. (a -> ()) -> NFData a
rnf :: Pragma -> ()
$crnf :: Pragma -> ()
NFData)

data Newtype name = Newtype
  { forall name. Newtype name -> Located name
nName     :: Located name        -- ^ Type name
  , forall name. Newtype name -> [TParam name]
nParams   :: [TParam name]       -- ^ Type params
  , forall name. Newtype name -> name
nConName  :: !name               -- ^ Constructor function name
  , forall name. Newtype name -> Rec (Type name)
nBody     :: Rec (Type name)     -- ^ Body
  } deriving (Newtype name -> Newtype name -> Bool
forall name. Eq name => Newtype name -> Newtype name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Newtype name -> Newtype name -> Bool
$c/= :: forall name. Eq name => Newtype name -> Newtype name -> Bool
== :: Newtype name -> Newtype name -> Bool
$c== :: forall name. Eq name => Newtype name -> Newtype name -> Bool
Eq, Int -> Newtype name -> ShowS
forall name. Show name => Int -> Newtype name -> ShowS
forall name. Show name => [Newtype name] -> ShowS
forall name. Show name => Newtype name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Newtype name] -> ShowS
$cshowList :: forall name. Show name => [Newtype name] -> ShowS
show :: Newtype name -> FilePath
$cshow :: forall name. Show name => Newtype name -> FilePath
showsPrec :: Int -> Newtype name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Newtype name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (Newtype name) x -> Newtype name
forall name x. Newtype name -> Rep (Newtype name) x
$cto :: forall name x. Rep (Newtype name) x -> Newtype name
$cfrom :: forall name x. Newtype name -> Rep (Newtype name) x
Generic, forall name. NFData name => Newtype name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Newtype name -> ()
$crnf :: forall name. NFData name => Newtype name -> ()
NFData)

-- | A declaration for a type with no implementation.
data PrimType name = PrimType { forall name. PrimType name -> Located name
primTName :: Located name
                              , forall name. PrimType name -> Located Kind
primTKind :: Located Kind
                              , forall name. PrimType name -> ([TParam name], [Prop name])
primTCts  :: ([TParam name], [Prop name])
                                -- ^ parameters are in the order used
                                -- by the type constructor.
                              , forall name. PrimType name -> Maybe Fixity
primTFixity :: Maybe Fixity
                              } deriving (Int -> PrimType name -> ShowS
forall name. Show name => Int -> PrimType name -> ShowS
forall name. Show name => [PrimType name] -> ShowS
forall name. Show name => PrimType name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PrimType name] -> ShowS
$cshowList :: forall name. Show name => [PrimType name] -> ShowS
show :: PrimType name -> FilePath
$cshow :: forall name. Show name => PrimType name -> FilePath
showsPrec :: Int -> PrimType name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> PrimType name -> ShowS
Show,forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (PrimType name) x -> PrimType name
forall name x. PrimType name -> Rep (PrimType name) x
$cto :: forall name x. Rep (PrimType name) x -> PrimType name
$cfrom :: forall name x. PrimType name -> Rep (PrimType name) x
Generic,forall name. NFData name => PrimType name -> ()
forall a. (a -> ()) -> NFData a
rnf :: PrimType name -> ()
$crnf :: forall name. NFData name => PrimType name -> ()
NFData)

-- | Input at the REPL, which can be an expression, a @let@
-- statement, or empty (possibly a comment).
data ReplInput name = ExprInput (Expr name)
                    | LetInput [Decl name]
                    | EmptyInput
                      deriving (ReplInput name -> ReplInput name -> Bool
forall name. Eq name => ReplInput name -> ReplInput name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ReplInput name -> ReplInput name -> Bool
$c/= :: forall name. Eq name => ReplInput name -> ReplInput name -> Bool
== :: ReplInput name -> ReplInput name -> Bool
$c== :: forall name. Eq name => ReplInput name -> ReplInput name -> Bool
Eq, Int -> ReplInput name -> ShowS
forall name. Show name => Int -> ReplInput name -> ShowS
forall name. Show name => [ReplInput name] -> ShowS
forall name. Show name => ReplInput name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ReplInput name] -> ShowS
$cshowList :: forall name. Show name => [ReplInput name] -> ShowS
show :: ReplInput name -> FilePath
$cshow :: forall name. Show name => ReplInput name -> FilePath
showsPrec :: Int -> ReplInput name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ReplInput name -> ShowS
Show)

-- | Export information for a declaration.
data ExportType = Public
                | Private
                  deriving (ExportType -> ExportType -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExportType -> ExportType -> Bool
$c/= :: ExportType -> ExportType -> Bool
== :: ExportType -> ExportType -> Bool
$c== :: ExportType -> ExportType -> Bool
Eq, Int -> ExportType -> ShowS
[ExportType] -> ShowS
ExportType -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [ExportType] -> ShowS
$cshowList :: [ExportType] -> ShowS
show :: ExportType -> FilePath
$cshow :: ExportType -> FilePath
showsPrec :: Int -> ExportType -> ShowS
$cshowsPrec :: Int -> ExportType -> ShowS
Show, Eq ExportType
ExportType -> ExportType -> Bool
ExportType -> ExportType -> Ordering
ExportType -> ExportType -> ExportType
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 :: ExportType -> ExportType -> ExportType
$cmin :: ExportType -> ExportType -> ExportType
max :: ExportType -> ExportType -> ExportType
$cmax :: ExportType -> ExportType -> ExportType
>= :: ExportType -> ExportType -> Bool
$c>= :: ExportType -> ExportType -> Bool
> :: ExportType -> ExportType -> Bool
$c> :: ExportType -> ExportType -> Bool
<= :: ExportType -> ExportType -> Bool
$c<= :: ExportType -> ExportType -> Bool
< :: ExportType -> ExportType -> Bool
$c< :: ExportType -> ExportType -> Bool
compare :: ExportType -> ExportType -> Ordering
$ccompare :: ExportType -> ExportType -> Ordering
Ord, forall x. Rep ExportType x -> ExportType
forall x. ExportType -> Rep ExportType x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExportType x -> ExportType
$cfrom :: forall x. ExportType -> Rep ExportType x
Generic, ExportType -> ()
forall a. (a -> ()) -> NFData a
rnf :: ExportType -> ()
$crnf :: ExportType -> ()
NFData)

-- | A top-level module declaration.
data TopLevel a = TopLevel { forall a. TopLevel a -> ExportType
tlExport :: ExportType
                           , forall a. TopLevel a -> Maybe (Located Text)
tlDoc    :: Maybe (Located Text)
                           , forall a. TopLevel a -> a
tlValue  :: a
                           }
  deriving (Int -> TopLevel a -> ShowS
forall a. Show a => Int -> TopLevel a -> ShowS
forall a. Show a => [TopLevel a] -> ShowS
forall a. Show a => TopLevel a -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [TopLevel a] -> ShowS
$cshowList :: forall a. Show a => [TopLevel a] -> ShowS
show :: TopLevel a -> FilePath
$cshow :: forall a. Show a => TopLevel a -> FilePath
showsPrec :: Int -> TopLevel a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> TopLevel a -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (TopLevel a) x -> TopLevel a
forall a x. TopLevel a -> Rep (TopLevel a) x
$cto :: forall a x. Rep (TopLevel a) x -> TopLevel a
$cfrom :: forall a x. TopLevel a -> Rep (TopLevel a) x
Generic, forall a. NFData a => TopLevel a -> ()
forall a. (a -> ()) -> NFData a
rnf :: TopLevel a -> ()
$crnf :: forall a. NFData a => TopLevel a -> ()
NFData, forall a b. a -> TopLevel b -> TopLevel a
forall a b. (a -> b) -> TopLevel a -> TopLevel b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> TopLevel b -> TopLevel a
$c<$ :: forall a b. a -> TopLevel b -> TopLevel a
fmap :: forall a b. (a -> b) -> TopLevel a -> TopLevel b
$cfmap :: forall a b. (a -> b) -> TopLevel a -> TopLevel b
Functor, forall a. Eq a => a -> TopLevel a -> Bool
forall a. Num a => TopLevel a -> a
forall a. Ord a => TopLevel a -> a
forall m. Monoid m => TopLevel m -> m
forall a. TopLevel a -> Bool
forall a. TopLevel a -> Int
forall a. TopLevel a -> [a]
forall a. (a -> a -> a) -> TopLevel a -> a
forall m a. Monoid m => (a -> m) -> TopLevel a -> m
forall b a. (b -> a -> b) -> b -> TopLevel a -> b
forall a b. (a -> b -> b) -> b -> TopLevel a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => TopLevel a -> a
$cproduct :: forall a. Num a => TopLevel a -> a
sum :: forall a. Num a => TopLevel a -> a
$csum :: forall a. Num a => TopLevel a -> a
minimum :: forall a. Ord a => TopLevel a -> a
$cminimum :: forall a. Ord a => TopLevel a -> a
maximum :: forall a. Ord a => TopLevel a -> a
$cmaximum :: forall a. Ord a => TopLevel a -> a
elem :: forall a. Eq a => a -> TopLevel a -> Bool
$celem :: forall a. Eq a => a -> TopLevel a -> Bool
length :: forall a. TopLevel a -> Int
$clength :: forall a. TopLevel a -> Int
null :: forall a. TopLevel a -> Bool
$cnull :: forall a. TopLevel a -> Bool
toList :: forall a. TopLevel a -> [a]
$ctoList :: forall a. TopLevel a -> [a]
foldl1 :: forall a. (a -> a -> a) -> TopLevel a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> TopLevel a -> a
foldr1 :: forall a. (a -> a -> a) -> TopLevel a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> TopLevel a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> TopLevel a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> TopLevel a -> b
foldl :: forall b a. (b -> a -> b) -> b -> TopLevel a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> TopLevel a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> TopLevel a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> TopLevel a -> b
foldr :: forall a b. (a -> b -> b) -> b -> TopLevel a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> TopLevel a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> TopLevel a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> TopLevel a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> TopLevel a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> TopLevel a -> m
fold :: forall m. Monoid m => TopLevel m -> m
$cfold :: forall m. Monoid m => TopLevel m -> m
Foldable, Functor TopLevel
Foldable TopLevel
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => TopLevel (m a) -> m (TopLevel a)
forall (f :: * -> *) a.
Applicative f =>
TopLevel (f a) -> f (TopLevel a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TopLevel a -> m (TopLevel b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TopLevel a -> f (TopLevel b)
sequence :: forall (m :: * -> *) a. Monad m => TopLevel (m a) -> m (TopLevel a)
$csequence :: forall (m :: * -> *) a. Monad m => TopLevel (m a) -> m (TopLevel a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TopLevel a -> m (TopLevel b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> TopLevel a -> m (TopLevel b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
TopLevel (f a) -> f (TopLevel a)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
TopLevel (f a) -> f (TopLevel a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TopLevel a -> f (TopLevel b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> TopLevel a -> f (TopLevel b)
Traversable)


-- | Infromation about the representation of a numeric constant.
data NumInfo  = BinLit Text Int                 -- ^ n-digit binary literal
              | OctLit Text Int                 -- ^ n-digit octal  literal
              | DecLit Text                     -- ^ overloaded decimal literal
              | HexLit Text Int                 -- ^ n-digit hex literal
              | PolyLit Int                     -- ^ polynomial literal
                deriving (NumInfo -> NumInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: NumInfo -> NumInfo -> Bool
$c/= :: NumInfo -> NumInfo -> Bool
== :: NumInfo -> NumInfo -> Bool
$c== :: NumInfo -> NumInfo -> Bool
Eq, Int -> NumInfo -> ShowS
[NumInfo] -> ShowS
NumInfo -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [NumInfo] -> ShowS
$cshowList :: [NumInfo] -> ShowS
show :: NumInfo -> FilePath
$cshow :: NumInfo -> FilePath
showsPrec :: Int -> NumInfo -> ShowS
$cshowsPrec :: Int -> NumInfo -> ShowS
Show, forall x. Rep NumInfo x -> NumInfo
forall x. NumInfo -> Rep NumInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep NumInfo x -> NumInfo
$cfrom :: forall x. NumInfo -> Rep NumInfo x
Generic, NumInfo -> ()
forall a. (a -> ()) -> NFData a
rnf :: NumInfo -> ()
$crnf :: NumInfo -> ()
NFData)

-- | Information about fractional literals.
data FracInfo = BinFrac Text
              | OctFrac Text
              | DecFrac Text
              | HexFrac Text
                deriving (FracInfo -> FracInfo -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FracInfo -> FracInfo -> Bool
$c/= :: FracInfo -> FracInfo -> Bool
== :: FracInfo -> FracInfo -> Bool
$c== :: FracInfo -> FracInfo -> Bool
Eq,Int -> FracInfo -> ShowS
[FracInfo] -> ShowS
FracInfo -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [FracInfo] -> ShowS
$cshowList :: [FracInfo] -> ShowS
show :: FracInfo -> FilePath
$cshow :: FracInfo -> FilePath
showsPrec :: Int -> FracInfo -> ShowS
$cshowsPrec :: Int -> FracInfo -> ShowS
Show,forall x. Rep FracInfo x -> FracInfo
forall x. FracInfo -> Rep FracInfo x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep FracInfo x -> FracInfo
$cfrom :: forall x. FracInfo -> Rep FracInfo x
Generic,FracInfo -> ()
forall a. (a -> ()) -> NFData a
rnf :: FracInfo -> ()
$crnf :: FracInfo -> ()
NFData)

-- | Literals.
data Literal  = ECNum Integer NumInfo           -- ^ @0x10@  (HexLit 2)
              | ECChar Char                     -- ^ @'a'@
              | ECFrac Rational FracInfo        -- ^ @1.2e3@
              | ECString String                 -- ^ @\"hello\"@
                deriving (Literal -> Literal -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Literal -> Literal -> Bool
$c/= :: Literal -> Literal -> Bool
== :: Literal -> Literal -> Bool
$c== :: Literal -> Literal -> Bool
Eq, Int -> Literal -> ShowS
[Literal] -> ShowS
Literal -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Literal] -> ShowS
$cshowList :: [Literal] -> ShowS
show :: Literal -> FilePath
$cshow :: Literal -> FilePath
showsPrec :: Int -> Literal -> ShowS
$cshowsPrec :: Int -> Literal -> ShowS
Show, forall x. Rep Literal x -> Literal
forall x. Literal -> Rep Literal x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Literal x -> Literal
$cfrom :: forall x. Literal -> Rep Literal x
Generic, Literal -> ()
forall a. (a -> ()) -> NFData a
rnf :: Literal -> ()
$crnf :: Literal -> ()
NFData)

data Expr n   = EVar n                          -- ^ @ x @
              | ELit Literal                    -- ^ @ 0x10 @
              | EGenerate (Expr n)              -- ^ @ generate f @
              | ETuple [Expr n]                 -- ^ @ (1,2,3) @
              | ERecord (Rec (Expr n))          -- ^ @ { x = 1, y = 2 } @
              | ESel (Expr n) Selector          -- ^ @ e.l @
              | EUpd (Maybe (Expr n)) [ UpdField n ]  -- ^ @ { r | x = e } @
              | EList [Expr n]                  -- ^ @ [1,2,3] @
              | EFromTo (Type n) (Maybe (Type n)) (Type n) (Maybe (Type n))
                                                -- ^ @ [1, 5 .. 117 : t] @
              | EFromToBy Bool (Type n) (Type n) (Type n) (Maybe (Type n))
                                                -- ^ @ [1 .. 10 by 2 : t ] @

              | EFromToDownBy Bool (Type n) (Type n) (Type n) (Maybe (Type n))
                                                -- ^ @ [10 .. 1 down by 2 : t ] @
              | EFromToLessThan (Type n) (Type n) (Maybe (Type n))
                                                -- ^ @ [ 1 .. < 10 : t ] @

              | EInfFrom (Expr n) (Maybe (Expr n))-- ^ @ [1, 3 ...] @
              | EComp (Expr n) [[Match n]]      -- ^ @ [ 1 | x <- xs ] @
              | EApp (Expr n) (Expr n)          -- ^ @ f x @
              | EAppT (Expr n) [(TypeInst n)]   -- ^ @ f `{x = 8}, f`{8} @
              | EIf (Expr n) (Expr n) (Expr n)  -- ^ @ if ok then e1 else e2 @
              | EWhere (Expr n) [Decl n]        -- ^ @ 1 + x where { x = 2 } @
              | ETyped (Expr n) (Type n)        -- ^ @ 1 : [8] @
              | ETypeVal (Type n)               -- ^ @ `(x + 1)@, @x@ is a type
              | EFun (FunDesc n) [Pattern n] (Expr n) -- ^ @ \\x y -> x @
              | ELocated (Expr n) Range         -- ^ position annotation

              | ESplit (Expr n)                 -- ^ @ splitAt x @ (Introduced by NoPat)
              | EParens (Expr n)                -- ^ @ (e)   @ (Removed by Fixity)
              | EInfix (Expr n) (Located n) Fixity (Expr n)-- ^ @ a + b @ (Removed by Fixity)
              | EPrefix PrefixOp (Expr n)       -- ^ @ -1, ~1 @
                deriving (Expr n -> Expr n -> Bool
forall n. Eq n => Expr n -> Expr n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Expr n -> Expr n -> Bool
$c/= :: forall n. Eq n => Expr n -> Expr n -> Bool
== :: Expr n -> Expr n -> Bool
$c== :: forall n. Eq n => Expr n -> Expr n -> Bool
Eq, Int -> Expr n -> ShowS
forall n. Show n => Int -> Expr n -> ShowS
forall n. Show n => [Expr n] -> ShowS
forall n. Show n => Expr n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Expr n] -> ShowS
$cshowList :: forall n. Show n => [Expr n] -> ShowS
show :: Expr n -> FilePath
$cshow :: forall n. Show n => Expr n -> FilePath
showsPrec :: Int -> Expr n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Expr n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (Expr n) x -> Expr n
forall n x. Expr n -> Rep (Expr n) x
$cto :: forall n x. Rep (Expr n) x -> Expr n
$cfrom :: forall n x. Expr n -> Rep (Expr n) x
Generic, forall n. NFData n => Expr n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Expr n -> ()
$crnf :: forall n. NFData n => Expr n -> ()
NFData, forall a b. a -> Expr b -> Expr a
forall a b. (a -> b) -> Expr a -> Expr b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Expr b -> Expr a
$c<$ :: forall a b. a -> Expr b -> Expr a
fmap :: forall a b. (a -> b) -> Expr a -> Expr b
$cfmap :: forall a b. (a -> b) -> Expr a -> Expr b
Functor)

-- | Prefix operator.
data PrefixOp = PrefixNeg -- ^ @ - @
              | PrefixComplement -- ^ @ ~ @
                deriving (PrefixOp -> PrefixOp -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PrefixOp -> PrefixOp -> Bool
$c/= :: PrefixOp -> PrefixOp -> Bool
== :: PrefixOp -> PrefixOp -> Bool
$c== :: PrefixOp -> PrefixOp -> Bool
Eq, Int -> PrefixOp -> ShowS
[PrefixOp] -> ShowS
PrefixOp -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [PrefixOp] -> ShowS
$cshowList :: [PrefixOp] -> ShowS
show :: PrefixOp -> FilePath
$cshow :: PrefixOp -> FilePath
showsPrec :: Int -> PrefixOp -> ShowS
$cshowsPrec :: Int -> PrefixOp -> ShowS
Show, forall x. Rep PrefixOp x -> PrefixOp
forall x. PrefixOp -> Rep PrefixOp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PrefixOp x -> PrefixOp
$cfrom :: forall x. PrefixOp -> Rep PrefixOp x
Generic, PrefixOp -> ()
forall a. (a -> ()) -> NFData a
rnf :: PrefixOp -> ()
$crnf :: PrefixOp -> ()
NFData)

prefixFixity :: PrefixOp -> Fixity
prefixFixity :: PrefixOp -> Fixity
prefixFixity PrefixOp
op = Fixity { fAssoc :: Assoc
fAssoc = Assoc
LeftAssoc, Int
fLevel :: Int
fLevel :: Int
.. }
  where fLevel :: Int
fLevel = case PrefixOp
op of
          PrefixOp
PrefixNeg        -> Int
80
          PrefixOp
PrefixComplement -> Int
100

-- | Description of functions.  Only trivial information is provided here
--   by the parser.  The NoPat pass fills this in as required.
data FunDesc n =
  FunDesc
  { forall n. FunDesc n -> Maybe n
funDescrName      :: Maybe n   -- ^ Name of this function, if it has one
  , forall n. FunDesc n -> Int
funDescrArgOffset :: Int -- ^ number of previous arguments to this function
                             --   bound in surrounding lambdas (defaults to 0)
  }
 deriving (FunDesc n -> FunDesc n -> Bool
forall n. Eq n => FunDesc n -> FunDesc n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: FunDesc n -> FunDesc n -> Bool
$c/= :: forall n. Eq n => FunDesc n -> FunDesc n -> Bool
== :: FunDesc n -> FunDesc n -> Bool
$c== :: forall n. Eq n => FunDesc n -> FunDesc n -> Bool
Eq, Int -> FunDesc n -> ShowS
forall n. Show n => Int -> FunDesc n -> ShowS
forall n. Show n => [FunDesc n] -> ShowS
forall n. Show n => FunDesc n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [FunDesc n] -> ShowS
$cshowList :: forall n. Show n => [FunDesc n] -> ShowS
show :: FunDesc n -> FilePath
$cshow :: forall n. Show n => FunDesc n -> FilePath
showsPrec :: Int -> FunDesc n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> FunDesc n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (FunDesc n) x -> FunDesc n
forall n x. FunDesc n -> Rep (FunDesc n) x
$cto :: forall n x. Rep (FunDesc n) x -> FunDesc n
$cfrom :: forall n x. FunDesc n -> Rep (FunDesc n) x
Generic, forall n. NFData n => FunDesc n -> ()
forall a. (a -> ()) -> NFData a
rnf :: FunDesc n -> ()
$crnf :: forall n. NFData n => FunDesc n -> ()
NFData, forall a b. a -> FunDesc b -> FunDesc a
forall a b. (a -> b) -> FunDesc a -> FunDesc b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> FunDesc b -> FunDesc a
$c<$ :: forall a b. a -> FunDesc b -> FunDesc a
fmap :: forall a b. (a -> b) -> FunDesc a -> FunDesc b
$cfmap :: forall a b. (a -> b) -> FunDesc a -> FunDesc b
Functor)

emptyFunDesc :: FunDesc n
emptyFunDesc :: forall n. FunDesc n
emptyFunDesc = forall n. Maybe n -> Int -> FunDesc n
FunDesc forall a. Maybe a
Nothing Int
0

data UpdField n = UpdField UpdHow [Located Selector] (Expr n)
                                                -- ^ non-empty list @ x.y = e@
                deriving (UpdField n -> UpdField n -> Bool
forall n. Eq n => UpdField n -> UpdField n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdField n -> UpdField n -> Bool
$c/= :: forall n. Eq n => UpdField n -> UpdField n -> Bool
== :: UpdField n -> UpdField n -> Bool
$c== :: forall n. Eq n => UpdField n -> UpdField n -> Bool
Eq, Int -> UpdField n -> ShowS
forall n. Show n => Int -> UpdField n -> ShowS
forall n. Show n => [UpdField n] -> ShowS
forall n. Show n => UpdField n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [UpdField n] -> ShowS
$cshowList :: forall n. Show n => [UpdField n] -> ShowS
show :: UpdField n -> FilePath
$cshow :: forall n. Show n => UpdField n -> FilePath
showsPrec :: Int -> UpdField n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> UpdField n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (UpdField n) x -> UpdField n
forall n x. UpdField n -> Rep (UpdField n) x
$cto :: forall n x. Rep (UpdField n) x -> UpdField n
$cfrom :: forall n x. UpdField n -> Rep (UpdField n) x
Generic, forall n. NFData n => UpdField n -> ()
forall a. (a -> ()) -> NFData a
rnf :: UpdField n -> ()
$crnf :: forall n. NFData n => UpdField n -> ()
NFData, forall a b. a -> UpdField b -> UpdField a
forall a b. (a -> b) -> UpdField a -> UpdField b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> UpdField b -> UpdField a
$c<$ :: forall a b. a -> UpdField b -> UpdField a
fmap :: forall a b. (a -> b) -> UpdField a -> UpdField b
$cfmap :: forall a b. (a -> b) -> UpdField a -> UpdField b
Functor)

data UpdHow     = UpdSet | UpdFun   -- ^ Are we setting or updating a field.
                deriving (UpdHow -> UpdHow -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: UpdHow -> UpdHow -> Bool
$c/= :: UpdHow -> UpdHow -> Bool
== :: UpdHow -> UpdHow -> Bool
$c== :: UpdHow -> UpdHow -> Bool
Eq, Int -> UpdHow -> ShowS
[UpdHow] -> ShowS
UpdHow -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [UpdHow] -> ShowS
$cshowList :: [UpdHow] -> ShowS
show :: UpdHow -> FilePath
$cshow :: UpdHow -> FilePath
showsPrec :: Int -> UpdHow -> ShowS
$cshowsPrec :: Int -> UpdHow -> ShowS
Show, forall x. Rep UpdHow x -> UpdHow
forall x. UpdHow -> Rep UpdHow x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep UpdHow x -> UpdHow
$cfrom :: forall x. UpdHow -> Rep UpdHow x
Generic, UpdHow -> ()
forall a. (a -> ()) -> NFData a
rnf :: UpdHow -> ()
$crnf :: UpdHow -> ()
NFData)

data TypeInst name = NamedInst (Named (Type name))
                   | PosInst (Type name)
                     deriving (TypeInst name -> TypeInst name -> Bool
forall name. Eq name => TypeInst name -> TypeInst name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TypeInst name -> TypeInst name -> Bool
$c/= :: forall name. Eq name => TypeInst name -> TypeInst name -> Bool
== :: TypeInst name -> TypeInst name -> Bool
$c== :: forall name. Eq name => TypeInst name -> TypeInst name -> Bool
Eq, Int -> TypeInst name -> ShowS
forall name. Show name => Int -> TypeInst name -> ShowS
forall name. Show name => [TypeInst name] -> ShowS
forall name. Show name => TypeInst name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [TypeInst name] -> ShowS
$cshowList :: forall name. Show name => [TypeInst name] -> ShowS
show :: TypeInst name -> FilePath
$cshow :: forall name. Show name => TypeInst name -> FilePath
showsPrec :: Int -> TypeInst name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> TypeInst name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (TypeInst name) x -> TypeInst name
forall name x. TypeInst name -> Rep (TypeInst name) x
$cto :: forall name x. Rep (TypeInst name) x -> TypeInst name
$cfrom :: forall name x. TypeInst name -> Rep (TypeInst name) x
Generic, forall name. NFData name => TypeInst name -> ()
forall a. (a -> ()) -> NFData a
rnf :: TypeInst name -> ()
$crnf :: forall name. NFData name => TypeInst name -> ()
NFData, forall a b. a -> TypeInst b -> TypeInst a
forall a b. (a -> b) -> TypeInst a -> TypeInst b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> TypeInst b -> TypeInst a
$c<$ :: forall a b. a -> TypeInst b -> TypeInst a
fmap :: forall a b. (a -> b) -> TypeInst a -> TypeInst b
$cfmap :: forall a b. (a -> b) -> TypeInst a -> TypeInst b
Functor)

data Match name = Match (Pattern name) (Expr name)              -- ^ p <- e
                | MatchLet (Bind name)
                  deriving (Match name -> Match name -> Bool
forall name. Eq name => Match name -> Match name -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Match name -> Match name -> Bool
$c/= :: forall name. Eq name => Match name -> Match name -> Bool
== :: Match name -> Match name -> Bool
$c== :: forall name. Eq name => Match name -> Match name -> Bool
Eq, Int -> Match name -> ShowS
forall name. Show name => Int -> Match name -> ShowS
forall name. Show name => [Match name] -> ShowS
forall name. Show name => Match name -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Match name] -> ShowS
$cshowList :: forall name. Show name => [Match name] -> ShowS
show :: Match name -> FilePath
$cshow :: forall name. Show name => Match name -> FilePath
showsPrec :: Int -> Match name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Match name -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall name x. Rep (Match name) x -> Match name
forall name x. Match name -> Rep (Match name) x
$cto :: forall name x. Rep (Match name) x -> Match name
$cfrom :: forall name x. Match name -> Rep (Match name) x
Generic, forall name. NFData name => Match name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Match name -> ()
$crnf :: forall name. NFData name => Match name -> ()
NFData, forall a b. a -> Match b -> Match a
forall a b. (a -> b) -> Match a -> Match b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Match b -> Match a
$c<$ :: forall a b. a -> Match b -> Match a
fmap :: forall a b. (a -> b) -> Match a -> Match b
$cfmap :: forall a b. (a -> b) -> Match a -> Match b
Functor)

data Pattern n = PVar (Located n)              -- ^ @ x @
               | PWild                         -- ^ @ _ @
               | PTuple [Pattern n]            -- ^ @ (x,y,z) @
               | PRecord (Rec (Pattern n))     -- ^ @ { x = (a,b,c), y = z } @
               | PList [ Pattern n ]           -- ^ @ [ x, y, z ] @
               | PTyped (Pattern n) (Type n)   -- ^ @ x : [8] @
               | PSplit (Pattern n) (Pattern n)-- ^ @ (x # y) @
               | PLocated (Pattern n) Range    -- ^ Location information
                 deriving (Pattern n -> Pattern n -> Bool
forall n. Eq n => Pattern n -> Pattern n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Pattern n -> Pattern n -> Bool
$c/= :: forall n. Eq n => Pattern n -> Pattern n -> Bool
== :: Pattern n -> Pattern n -> Bool
$c== :: forall n. Eq n => Pattern n -> Pattern n -> Bool
Eq, Int -> Pattern n -> ShowS
forall n. Show n => Int -> Pattern n -> ShowS
forall n. Show n => [Pattern n] -> ShowS
forall n. Show n => Pattern n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Pattern n] -> ShowS
$cshowList :: forall n. Show n => [Pattern n] -> ShowS
show :: Pattern n -> FilePath
$cshow :: forall n. Show n => Pattern n -> FilePath
showsPrec :: Int -> Pattern n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Pattern n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (Pattern n) x -> Pattern n
forall n x. Pattern n -> Rep (Pattern n) x
$cto :: forall n x. Rep (Pattern n) x -> Pattern n
$cfrom :: forall n x. Pattern n -> Rep (Pattern n) x
Generic, forall n. NFData n => Pattern n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Pattern n -> ()
$crnf :: forall n. NFData n => Pattern n -> ()
NFData, forall a b. a -> Pattern b -> Pattern a
forall a b. (a -> b) -> Pattern a -> Pattern b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Pattern b -> Pattern a
$c<$ :: forall a b. a -> Pattern b -> Pattern a
fmap :: forall a b. (a -> b) -> Pattern a -> Pattern b
$cfmap :: forall a b. (a -> b) -> Pattern a -> Pattern b
Functor)

data Named a = Named { forall a. Named a -> Located Ident
name :: Located Ident, forall a. Named a -> a
value :: a }
  deriving (Named a -> Named a -> Bool
forall a. Eq a => Named a -> Named a -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Named a -> Named a -> Bool
$c/= :: forall a. Eq a => Named a -> Named a -> Bool
== :: Named a -> Named a -> Bool
$c== :: forall a. Eq a => Named a -> Named a -> Bool
Eq, Int -> Named a -> ShowS
forall a. Show a => Int -> Named a -> ShowS
forall a. Show a => [Named a] -> ShowS
forall a. Show a => Named a -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Named a] -> ShowS
$cshowList :: forall a. Show a => [Named a] -> ShowS
show :: Named a -> FilePath
$cshow :: forall a. Show a => Named a -> FilePath
showsPrec :: Int -> Named a -> ShowS
$cshowsPrec :: forall a. Show a => Int -> Named a -> ShowS
Show, forall a. Eq a => a -> Named a -> Bool
forall a. Num a => Named a -> a
forall a. Ord a => Named a -> a
forall m. Monoid m => Named m -> m
forall a. Named a -> Bool
forall a. Named a -> Int
forall a. Named a -> [a]
forall a. (a -> a -> a) -> Named a -> a
forall m a. Monoid m => (a -> m) -> Named a -> m
forall b a. (b -> a -> b) -> b -> Named a -> b
forall a b. (a -> b -> b) -> b -> Named a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => Named a -> a
$cproduct :: forall a. Num a => Named a -> a
sum :: forall a. Num a => Named a -> a
$csum :: forall a. Num a => Named a -> a
minimum :: forall a. Ord a => Named a -> a
$cminimum :: forall a. Ord a => Named a -> a
maximum :: forall a. Ord a => Named a -> a
$cmaximum :: forall a. Ord a => Named a -> a
elem :: forall a. Eq a => a -> Named a -> Bool
$celem :: forall a. Eq a => a -> Named a -> Bool
length :: forall a. Named a -> Int
$clength :: forall a. Named a -> Int
null :: forall a. Named a -> Bool
$cnull :: forall a. Named a -> Bool
toList :: forall a. Named a -> [a]
$ctoList :: forall a. Named a -> [a]
foldl1 :: forall a. (a -> a -> a) -> Named a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Named a -> a
foldr1 :: forall a. (a -> a -> a) -> Named a -> a
$cfoldr1 :: forall a. (a -> a -> a) -> Named a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> Named a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Named a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Named a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Named a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Named a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Named a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Named a -> b
$cfoldr :: forall a b. (a -> b -> b) -> b -> Named a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> Named a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Named a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Named a -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Named a -> m
fold :: forall m. Monoid m => Named m -> m
$cfold :: forall m. Monoid m => Named m -> m
Foldable, Functor Named
Foldable Named
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Named (m a) -> m (Named a)
forall (f :: * -> *) a. Applicative f => Named (f a) -> f (Named a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named a -> m (Named b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named a -> f (Named b)
sequence :: forall (m :: * -> *) a. Monad m => Named (m a) -> m (Named a)
$csequence :: forall (m :: * -> *) a. Monad m => Named (m a) -> m (Named a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named a -> m (Named b)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Named a -> m (Named b)
sequenceA :: forall (f :: * -> *) a. Applicative f => Named (f a) -> f (Named a)
$csequenceA :: forall (f :: * -> *) a. Applicative f => Named (f a) -> f (Named a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named a -> f (Named b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Named a -> f (Named b)
Traversable, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall a x. Rep (Named a) x -> Named a
forall a x. Named a -> Rep (Named a) x
$cto :: forall a x. Rep (Named a) x -> Named a
$cfrom :: forall a x. Named a -> Rep (Named a) x
Generic, forall a. NFData a => Named a -> ()
forall a. (a -> ()) -> NFData a
rnf :: Named a -> ()
$crnf :: forall a. NFData a => Named a -> ()
NFData, forall a b. a -> Named b -> Named a
forall a b. (a -> b) -> Named a -> Named b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Named b -> Named a
$c<$ :: forall a b. a -> Named b -> Named a
fmap :: forall a b. (a -> b) -> Named a -> Named b
$cfmap :: forall a b. (a -> b) -> Named a -> Named b
Functor)

data Schema n = Forall [TParam n] [Prop n] (Type n) (Maybe Range)
  deriving (Schema n -> Schema n -> Bool
forall n. Eq n => Schema n -> Schema n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Schema n -> Schema n -> Bool
$c/= :: forall n. Eq n => Schema n -> Schema n -> Bool
== :: Schema n -> Schema n -> Bool
$c== :: forall n. Eq n => Schema n -> Schema n -> Bool
Eq, Int -> Schema n -> ShowS
forall n. Show n => Int -> Schema n -> ShowS
forall n. Show n => [Schema n] -> ShowS
forall n. Show n => Schema n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Schema n] -> ShowS
$cshowList :: forall n. Show n => [Schema n] -> ShowS
show :: Schema n -> FilePath
$cshow :: forall n. Show n => Schema n -> FilePath
showsPrec :: Int -> Schema n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Schema n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (Schema n) x -> Schema n
forall n x. Schema n -> Rep (Schema n) x
$cto :: forall n x. Rep (Schema n) x -> Schema n
$cfrom :: forall n x. Schema n -> Rep (Schema n) x
Generic, forall n. NFData n => Schema n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Schema n -> ()
$crnf :: forall n. NFData n => Schema n -> ()
NFData, forall a b. a -> Schema b -> Schema a
forall a b. (a -> b) -> Schema a -> Schema b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Schema b -> Schema a
$c<$ :: forall a b. a -> Schema b -> Schema a
fmap :: forall a b. (a -> b) -> Schema a -> Schema b
$cfmap :: forall a b. (a -> b) -> Schema a -> Schema b
Functor)

data Kind = KProp | KNum | KType | KFun Kind Kind
  deriving (Kind -> Kind -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Kind -> Kind -> Bool
$c/= :: Kind -> Kind -> Bool
== :: Kind -> Kind -> Bool
$c== :: Kind -> Kind -> Bool
Eq, Int -> Kind -> ShowS
[Kind] -> ShowS
Kind -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Kind] -> ShowS
$cshowList :: [Kind] -> ShowS
show :: Kind -> FilePath
$cshow :: Kind -> FilePath
showsPrec :: Int -> Kind -> ShowS
$cshowsPrec :: Int -> Kind -> ShowS
Show, forall x. Rep Kind x -> Kind
forall x. Kind -> Rep Kind x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Kind x -> Kind
$cfrom :: forall x. Kind -> Rep Kind x
Generic, Kind -> ()
forall a. (a -> ()) -> NFData a
rnf :: Kind -> ()
$crnf :: Kind -> ()
NFData)

data TParam n = TParam { forall n. TParam n -> n
tpName  :: n
                       , forall n. TParam n -> Maybe Kind
tpKind  :: Maybe Kind
                       , forall n. TParam n -> Maybe Range
tpRange :: Maybe Range
                       }
  deriving (TParam n -> TParam n -> Bool
forall n. Eq n => TParam n -> TParam n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TParam n -> TParam n -> Bool
$c/= :: forall n. Eq n => TParam n -> TParam n -> Bool
== :: TParam n -> TParam n -> Bool
$c== :: forall n. Eq n => TParam n -> TParam n -> Bool
Eq, Int -> TParam n -> ShowS
forall n. Show n => Int -> TParam n -> ShowS
forall n. Show n => [TParam n] -> ShowS
forall n. Show n => TParam n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [TParam n] -> ShowS
$cshowList :: forall n. Show n => [TParam n] -> ShowS
show :: TParam n -> FilePath
$cshow :: forall n. Show n => TParam n -> FilePath
showsPrec :: Int -> TParam n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> TParam n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (TParam n) x -> TParam n
forall n x. TParam n -> Rep (TParam n) x
$cto :: forall n x. Rep (TParam n) x -> TParam n
$cfrom :: forall n x. TParam n -> Rep (TParam n) x
Generic, forall n. NFData n => TParam n -> ()
forall a. (a -> ()) -> NFData a
rnf :: TParam n -> ()
$crnf :: forall n. NFData n => TParam n -> ()
NFData, forall a b. a -> TParam b -> TParam a
forall a b. (a -> b) -> TParam a -> TParam b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> TParam b -> TParam a
$c<$ :: forall a b. a -> TParam b -> TParam a
fmap :: forall a b. (a -> b) -> TParam a -> TParam b
$cfmap :: forall a b. (a -> b) -> TParam a -> TParam b
Functor)

data Type n = TFun (Type n) (Type n)  -- ^ @[8] -> [8]@
            | TSeq (Type n) (Type n)  -- ^ @[8] a@
            | TBit                    -- ^ @Bit@
            | TNum Integer            -- ^ @10@
            | TChar Char              -- ^ @'a'@
            | TUser n [Type n]        -- ^ A type variable or synonym
            | TTyApp [Named (Type n)] -- ^ @`{ x = [8], y = Integer }@
            | TRecord (Rec (Type n))  -- ^ @{ x : [8], y : [32] }@
            | TTuple [Type n]         -- ^ @([8], [32])@
            | TWild                   -- ^ @_@, just some type.
            | TLocated (Type n) Range -- ^ Location information
            | TParens (Type n) (Maybe Kind)       -- ^ @ (ty) @
            | TInfix (Type n) (Located n) Fixity (Type n) -- ^ @ ty + ty @
              deriving (Type n -> Type n -> Bool
forall n. Eq n => Type n -> Type n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Type n -> Type n -> Bool
$c/= :: forall n. Eq n => Type n -> Type n -> Bool
== :: Type n -> Type n -> Bool
$c== :: forall n. Eq n => Type n -> Type n -> Bool
Eq, Int -> Type n -> ShowS
forall n. Show n => Int -> Type n -> ShowS
forall n. Show n => [Type n] -> ShowS
forall n. Show n => Type n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Type n] -> ShowS
$cshowList :: forall n. Show n => [Type n] -> ShowS
show :: Type n -> FilePath
$cshow :: forall n. Show n => Type n -> FilePath
showsPrec :: Int -> Type n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Type n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (Type n) x -> Type n
forall n x. Type n -> Rep (Type n) x
$cto :: forall n x. Rep (Type n) x -> Type n
$cfrom :: forall n x. Type n -> Rep (Type n) x
Generic, forall n. NFData n => Type n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Type n -> ()
$crnf :: forall n. NFData n => Type n -> ()
NFData, forall a b. a -> Type b -> Type a
forall a b. (a -> b) -> Type a -> Type b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Type b -> Type a
$c<$ :: forall a b. a -> Type b -> Type a
fmap :: forall a b. (a -> b) -> Type a -> Type b
$cfmap :: forall a b. (a -> b) -> Type a -> Type b
Functor)

-- | A 'Prop' is a 'Type' that represents a type constraint.
newtype Prop n = CType (Type n)
  deriving (Prop n -> Prop n -> Bool
forall n. Eq n => Prop n -> Prop n -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Prop n -> Prop n -> Bool
$c/= :: forall n. Eq n => Prop n -> Prop n -> Bool
== :: Prop n -> Prop n -> Bool
$c== :: forall n. Eq n => Prop n -> Prop n -> Bool
Eq, Int -> Prop n -> ShowS
forall n. Show n => Int -> Prop n -> ShowS
forall n. Show n => [Prop n] -> ShowS
forall n. Show n => Prop n -> FilePath
forall a.
(Int -> a -> ShowS) -> (a -> FilePath) -> ([a] -> ShowS) -> Show a
showList :: [Prop n] -> ShowS
$cshowList :: forall n. Show n => [Prop n] -> ShowS
show :: Prop n -> FilePath
$cshow :: forall n. Show n => Prop n -> FilePath
showsPrec :: Int -> Prop n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Prop n -> ShowS
Show, forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall n x. Rep (Prop n) x -> Prop n
forall n x. Prop n -> Rep (Prop n) x
$cto :: forall n x. Rep (Prop n) x -> Prop n
$cfrom :: forall n x. Prop n -> Rep (Prop n) x
Generic, forall n. NFData n => Prop n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Prop n -> ()
$crnf :: forall n. NFData n => Prop n -> ()
NFData, forall a b. a -> Prop b -> Prop a
forall a b. (a -> b) -> Prop a -> Prop b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> Prop b -> Prop a
$c<$ :: forall a b. a -> Prop b -> Prop a
fmap :: forall a b. (a -> b) -> Prop a -> Prop b
$cfmap :: forall a b. (a -> b) -> Prop a -> Prop b
Functor)


--------------------------------------------------------------------------------
-- Note: When an explicit location is missing, we could use the sub-components
-- to try to estimate a location...


instance AddLoc (Expr n) where
  addLoc :: Expr n -> Range -> Expr n
addLoc x :: Expr n
x@ELocated{} Range
_ = Expr n
x
  addLoc Expr n
x            Range
r = forall n. Expr n -> Range -> Expr n
ELocated Expr n
x Range
r

  dropLoc :: Expr n -> Expr n
dropLoc (ELocated Expr n
e Range
_) = forall t. AddLoc t => t -> t
dropLoc Expr n
e
  dropLoc Expr n
e              = Expr n
e

instance HasLoc (Expr name) where
  getLoc :: Expr name -> Maybe Range
getLoc (ELocated Expr name
_ Range
r) = forall a. a -> Maybe a
Just Range
r
  getLoc Expr name
_              = forall a. Maybe a
Nothing

instance HasLoc (TParam name) where
  getLoc :: TParam name -> Maybe Range
getLoc (TParam name
_ Maybe Kind
_ Maybe Range
r) = Maybe Range
r

instance AddLoc (TParam name) where
  addLoc :: TParam name -> Range -> TParam name
addLoc (TParam name
a Maybe Kind
b Maybe Range
_) Range
l = forall n. n -> Maybe Kind -> Maybe Range -> TParam n
TParam name
a Maybe Kind
b (forall a. a -> Maybe a
Just Range
l)
  dropLoc :: TParam name -> TParam name
dropLoc (TParam name
a Maybe Kind
b Maybe Range
_)  = forall n. n -> Maybe Kind -> Maybe Range -> TParam n
TParam name
a Maybe Kind
b forall a. Maybe a
Nothing

instance HasLoc (Type name) where
  getLoc :: Type name -> Maybe Range
getLoc (TLocated Type name
_ Range
r) = forall a. a -> Maybe a
Just Range
r
  getLoc Type name
_              = forall a. Maybe a
Nothing

instance AddLoc (Type name) where
  addLoc :: Type name -> Range -> Type name
addLoc = forall name. Type name -> Range -> Type name
TLocated

  dropLoc :: Type name -> Type name
dropLoc (TLocated Type name
e Range
_) = forall t. AddLoc t => t -> t
dropLoc Type name
e
  dropLoc Type name
e              = Type name
e

instance AddLoc (Pattern name) where
  addLoc :: Pattern name -> Range -> Pattern name
addLoc = forall name. Pattern name -> Range -> Pattern name
PLocated

  dropLoc :: Pattern name -> Pattern name
dropLoc (PLocated Pattern name
e Range
_) = forall t. AddLoc t => t -> t
dropLoc Pattern name
e
  dropLoc Pattern name
e              = Pattern name
e

instance HasLoc (Pattern name) where
  getLoc :: Pattern name -> Maybe Range
getLoc (PLocated Pattern name
_ Range
r) = forall a. a -> Maybe a
Just Range
r
  getLoc (PTyped Pattern name
r Type name
_)   = forall t. HasLoc t => t -> Maybe Range
getLoc Pattern name
r
  getLoc (PVar Located name
x)       = forall t. HasLoc t => t -> Maybe Range
getLoc Located name
x
  getLoc Pattern name
_              = forall a. Maybe a
Nothing

instance HasLoc (Bind name) where
  getLoc :: Bind name -> Maybe Range
getLoc Bind name
b = forall t. HasLoc t => t -> Maybe Range
getLoc (forall name. Bind name -> Located name
bName Bind name
b, forall name. Bind name -> Located (BindDef name)
bDef Bind name
b)

instance HasLoc (Match name) where
  getLoc :: Match name -> Maybe Range
getLoc (Match Pattern name
p Expr name
e)    = forall t. HasLoc t => t -> Maybe Range
getLoc (Pattern name
p,Expr name
e)
  getLoc (MatchLet Bind name
b)   = forall t. HasLoc t => t -> Maybe Range
getLoc Bind name
b

instance HasLoc a => HasLoc (Named a) where
  getLoc :: Named a -> Maybe Range
getLoc Named a
l = forall t. HasLoc t => t -> Maybe Range
getLoc (forall a. Named a -> Located Ident
name Named a
l, forall a. Named a -> a
value Named a
l)

instance HasLoc (Schema name) where
  getLoc :: Schema name -> Maybe Range
getLoc (Forall [TParam name]
_ [Prop name]
_ Type name
_ Maybe Range
r) = Maybe Range
r

instance AddLoc (Schema name) where
  addLoc :: Schema name -> Range -> Schema name
addLoc  (Forall [TParam name]
xs [Prop name]
ps Type name
t Maybe Range
_) Range
r = forall n.
[TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
Forall [TParam name]
xs [Prop name]
ps Type name
t (forall a. a -> Maybe a
Just Range
r)
  dropLoc :: Schema name -> Schema name
dropLoc (Forall [TParam name]
xs [Prop name]
ps Type name
t Maybe Range
_)   = forall n.
[TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
Forall [TParam name]
xs [Prop name]
ps Type name
t forall a. Maybe a
Nothing

instance HasLoc (Decl name) where
  getLoc :: Decl name -> Maybe Range
getLoc (DLocated Decl name
_ Range
r) = forall a. a -> Maybe a
Just Range
r
  getLoc Decl name
_              = forall a. Maybe a
Nothing

instance AddLoc (Decl name) where
  addLoc :: Decl name -> Range -> Decl name
addLoc Decl name
d Range
r             = forall name. Decl name -> Range -> Decl name
DLocated Decl name
d Range
r

  dropLoc :: Decl name -> Decl name
dropLoc (DLocated Decl name
d Range
_) = forall t. AddLoc t => t -> t
dropLoc Decl name
d
  dropLoc Decl name
d              = Decl name
d

instance HasLoc a => HasLoc (TopLevel a) where
  getLoc :: TopLevel a -> Maybe Range
getLoc = forall t. HasLoc t => t -> Maybe Range
getLoc forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. TopLevel a -> a
tlValue

instance HasLoc (TopDecl name) where
  getLoc :: TopDecl name -> Maybe Range
getLoc TopDecl name
td =
    case TopDecl name
td of
      Decl TopLevel (Decl name)
tld    -> forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (Decl name)
tld
      DPrimType TopLevel (PrimType name)
pt -> forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (PrimType name)
pt
      TDNewtype TopLevel (Newtype name)
n -> forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (Newtype name)
n
      Include Located FilePath
lfp -> forall t. HasLoc t => t -> Maybe Range
getLoc Located FilePath
lfp
      DModule TopLevel (NestedModule name)
d -> forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (NestedModule name)
d
      DImport Located (ImportG (ImpName name))
d -> forall t. HasLoc t => t -> Maybe Range
getLoc Located (ImportG (ImpName name))
d
      DModParam ModParam name
d -> forall t. HasLoc t => t -> Maybe Range
getLoc ModParam name
d
      DParamDecl Range
r Signature name
_ -> forall a. a -> Maybe a
Just Range
r
      DInterfaceConstraint Maybe Text
_ Located [Prop name]
ds -> forall t. HasLoc t => t -> Maybe Range
getLoc Located [Prop name]
ds

instance HasLoc (ParamDecl name) where
  getLoc :: ParamDecl name -> Maybe Range
getLoc ParamDecl name
pd =
    case ParamDecl name
pd of
      DParameterType ParameterType name
d -> forall t. HasLoc t => t -> Maybe Range
getLoc ParameterType name
d
      DParameterFun ParameterFun name
d  -> forall t. HasLoc t => t -> Maybe Range
getLoc ParameterFun name
d
      DParameterDecl SigDecl name
d -> forall t. HasLoc t => t -> Maybe Range
getLoc SigDecl name
d
      DParameterConstraint [Located (Prop name)]
d -> forall t. HasLoc t => t -> Maybe Range
getLoc [Located (Prop name)]
d

instance HasLoc (SigDecl name) where
  getLoc :: SigDecl name -> Maybe Range
getLoc SigDecl name
decl =
    case SigDecl name
decl of
      SigTySyn TySyn name
ts Maybe Text
_    -> forall t. HasLoc t => t -> Maybe Range
getLoc TySyn name
ts
      SigPropSyn PropSyn name
ps Maybe Text
_  -> forall t. HasLoc t => t -> Maybe Range
getLoc PropSyn name
ps

instance HasLoc (ModParam name) where
  getLoc :: ModParam name -> Maybe Range
getLoc ModParam name
mp = forall t. HasLoc t => t -> Maybe Range
getLoc (forall name. ModParam name -> Located (ImpName name)
mpSignature ModParam name
mp)

instance HasLoc (PrimType name) where
  getLoc :: PrimType name -> Maybe Range
getLoc PrimType name
pt = forall a. a -> Maybe a
Just (Range -> Range -> Range
rComb (forall a. Located a -> Range
srcRange (forall name. PrimType name -> Located name
primTName PrimType name
pt)) (forall a. Located a -> Range
srcRange (forall name. PrimType name -> Located Kind
primTKind PrimType name
pt)))

instance HasLoc (ParameterType name) where
  getLoc :: ParameterType name -> Maybe Range
getLoc ParameterType name
a = forall t. HasLoc t => t -> Maybe Range
getLoc (forall name. ParameterType name -> Located name
ptName ParameterType name
a)

instance HasLoc (ParameterFun name) where
  getLoc :: ParameterFun name -> Maybe Range
getLoc ParameterFun name
a = forall t. HasLoc t => t -> Maybe Range
getLoc (forall name. ParameterFun name -> Located name
pfName ParameterFun name
a)

instance HasLoc (ModuleG mname name) where
  getLoc :: ModuleG mname name -> Maybe Range
getLoc ModuleG mname name
m
    | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Range]
locs = forall a. Maybe a
Nothing
    | Bool
otherwise = forall a. a -> Maybe a
Just ([Range] -> Range
rCombs [Range]
locs)
    where
    locs :: [Range]
locs = forall a. [Maybe a] -> [a]
catMaybes [ forall t. HasLoc t => t -> Maybe Range
getLoc (forall mname name. ModuleG mname name -> Located mname
mName ModuleG mname name
m)
                     , forall t. HasLoc t => t -> Maybe Range
getLoc (forall mname name. ModuleG mname name -> [Located Import]
mImports ModuleG mname name
m)
                     , forall t. HasLoc t => t -> Maybe Range
getLoc (forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m)
                     ]

instance HasLoc (NestedModule name) where
  getLoc :: NestedModule name -> Maybe Range
getLoc (NestedModule ModuleG name name
m) = forall t. HasLoc t => t -> Maybe Range
getLoc ModuleG name name
m

instance HasLoc (Newtype name) where
  getLoc :: Newtype name -> Maybe Range
getLoc Newtype name
n
    | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Range]
locs = forall a. Maybe a
Nothing
    | Bool
otherwise = forall a. a -> Maybe a
Just ([Range] -> Range
rCombs [Range]
locs)
    where
    locs :: [Range]
locs = forall a. [Maybe a] -> [a]
catMaybes ([ forall t. HasLoc t => t -> Maybe Range
getLoc (forall name. Newtype name -> Located name
nName Newtype name
n)] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a. a -> Maybe a
Just forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> b
snd) (forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields (forall name. Newtype name -> Rec (Type name)
nBody Newtype name
n)))

instance HasLoc (TySyn name) where
  getLoc :: TySyn name -> Maybe Range
getLoc (TySyn Located name
x Maybe Fixity
_ [TParam name]
_ Type name
_) = forall t. HasLoc t => t -> Maybe Range
getLoc Located name
x

instance HasLoc (PropSyn name) where
  getLoc :: PropSyn name -> Maybe Range
getLoc (PropSyn Located name
x Maybe Fixity
_ [TParam name]
_ [Prop name]
_) = forall t. HasLoc t => t -> Maybe Range
getLoc Located name
x



--------------------------------------------------------------------------------





--------------------------------------------------------------------------------
-- Pretty printing


ppL :: PP a => Located a -> Doc
ppL :: forall a. PP a => Located a -> Doc
ppL = forall a. PP a => a -> Doc
pp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Located a -> a
thing

ppNamed :: PP a => String -> Named a -> Doc
ppNamed :: forall a. PP a => FilePath -> Named a -> Doc
ppNamed FilePath
s Named a
x = forall a. PP a => Located a -> Doc
ppL (forall a. Named a -> Located Ident
name Named a
x) Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
s Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall a. Named a -> a
value Named a
x)

ppNamed' :: PP a => String -> (Ident, (Range, a)) -> Doc
ppNamed' :: forall a. PP a => FilePath -> (Ident, (Range, a)) -> Doc
ppNamed' FilePath
s (Ident
i,(Range
_,a
v)) = forall a. PP a => a -> Doc
pp Ident
i Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
s Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp a
v



instance (Show name, PPName mname, PPName name) => PP (ModuleG mname name) where
  ppPrec :: Int -> ModuleG mname name -> Doc
ppPrec Int
_ = forall name mname.
(Show name, PPName mname, PPName name) =>
Doc -> ModuleG mname name -> Doc
ppModule Doc
"module"

instance (Show name, PPName name) => PP (NestedModule name) where
  ppPrec :: Int -> NestedModule name -> Doc
ppPrec Int
_ (NestedModule ModuleG name name
m) = forall name mname.
(Show name, PPName mname, PPName name) =>
Doc -> ModuleG mname name -> Doc
ppModule Doc
"submodule" ModuleG name name
m

ppModule :: (Show name, PPName mname, PPName name) =>
  Doc -> ModuleG mname name -> Doc
ppModule :: forall name mname.
(Show name, PPName mname, PPName name) =>
Doc -> ModuleG mname name -> Doc
ppModule Doc
kw ModuleG mname name
m = Doc
kw' Doc -> Doc -> Doc
<+> forall a. PP a => Located a -> Doc
ppL (forall mname name. ModuleG mname name -> Located mname
mName ModuleG mname name
m) Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall mname name. ModuleG mname name -> ModuleDefinition name
mDef ModuleG mname name
m)
  where
  kw' :: Doc
kw' = case forall mname name. ModuleG mname name -> ModuleDefinition name
mDef ModuleG mname name
m of
          InterfaceModule {} -> Doc
"interface" Doc -> Doc -> Doc
<+> Doc
kw
          ModuleDefinition name
_                  -> Doc
kw


instance (Show name, PPName name) => PP (ModuleDefinition name) where
  ppPrec :: Int -> ModuleDefinition name -> Doc
ppPrec Int
_ ModuleDefinition name
def =
    case ModuleDefinition name
def of
      NormalModule [TopDecl name]
ds -> Doc
"where" Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
indent Int
2 ([Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [TopDecl name]
ds))
      FunctorInstance Located (ImpName name)
f ModuleInstanceArgs name
as ModuleInstance name
inst -> [Doc] -> Doc
vcat ( (Doc
"=" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located (ImpName name)
f) Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp ModuleInstanceArgs name
as)
                                        forall a. a -> [a] -> [a]
: [Doc]
ppInst
                                        )
        where
        ppInst :: [Doc]
ppInst    = if forall (t :: * -> *) a. Foldable t => t a -> Bool
null ModuleInstance name
inst then [] else [ Int -> Doc -> Doc
indent Int
2
                                                  ([Doc] -> Doc
vcat (Doc
"/* Instance:" forall a. a -> [a] -> [a]
:
                                                        [Doc]
instLines forall a. [a] -> [a] -> [a]
++ [Doc
" */"]))
                                              ]
        instLines :: [Doc]
instLines = [ Doc
" *" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp name
k Doc -> Doc -> Doc
<+> Doc
"->" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp name
v
                    | (name
k,name
v) <- forall k a. Map k a -> [(k, a)]
Map.toList ModuleInstance name
inst ]
      InterfaceModule Signature name
s -> forall name.
(Show name, PPName name) =>
Doc -> Signature name -> Doc
ppInterface Doc
"where" Signature name
s


instance (Show name, PPName name) => PP (ModuleInstanceArgs name) where
  ppPrec :: Int -> ModuleInstanceArgs name -> Doc
ppPrec Int
_ ModuleInstanceArgs name
arg =
    case ModuleInstanceArgs name
arg of
      DefaultInstArg Located (ModuleInstanceArg name)
x -> Doc -> Doc
braces (forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located (ModuleInstanceArg name)
x))
      DefaultInstAnonArg [TopDecl name]
ds -> Doc
"where" Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
indent Int
2 ([Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [TopDecl name]
ds))
      NamedInstArgs [ModuleInstanceNamedArg name]
xs -> Doc -> Doc
braces ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [ModuleInstanceNamedArg name]
xs))

instance (Show name, PPName name) => PP (ModuleInstanceNamedArg name) where
  ppPrec :: Int -> ModuleInstanceNamedArg name -> Doc
ppPrec Int
_ (ModuleInstanceNamedArg Located Ident
x Located (ModuleInstanceArg name)
y) = forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located Ident
x) Doc -> Doc -> Doc
<+> Doc
"=" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located (ModuleInstanceArg name)
y)


instance (Show name, PPName name) => PP (ModuleInstanceArg name) where
  ppPrec :: Int -> ModuleInstanceArg name -> Doc
ppPrec Int
_ ModuleInstanceArg name
arg =
    case ModuleInstanceArg name
arg of
      ModuleArg ImpName name
x    -> forall a. PP a => a -> Doc
pp ImpName name
x
      ParameterArg Ident
i -> Doc
"parameter" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Ident
i
      ModuleInstanceArg name
AddParams      -> Doc
"{}"


instance (Show name, PPName name) => PP (Program name) where
  ppPrec :: Int -> Program name -> Doc
ppPrec Int
_ (Program [TopDecl name]
ds) = [Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [TopDecl name]
ds)

instance (Show name, PPName name) => PP (TopDecl name) where
  ppPrec :: Int -> TopDecl name -> Doc
ppPrec Int
_ TopDecl name
top_decl =
    case TopDecl name
top_decl of
      Decl    TopLevel (Decl name)
d   -> forall a. PP a => a -> Doc
pp TopLevel (Decl name)
d
      DPrimType TopLevel (PrimType name)
p -> forall a. PP a => a -> Doc
pp TopLevel (PrimType name)
p
      TDNewtype TopLevel (Newtype name)
n -> forall a. PP a => a -> Doc
pp TopLevel (Newtype name)
n
      Include Located FilePath
l   -> FilePath -> Doc
text FilePath
"include" Doc -> Doc -> Doc
<+> FilePath -> Doc
text (forall a. Show a => a -> FilePath
show (forall a. Located a -> a
thing Located FilePath
l))
      DModule TopLevel (NestedModule name)
d -> forall a. PP a => a -> Doc
pp TopLevel (NestedModule name)
d
      DImport Located (ImportG (ImpName name))
i -> forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located (ImportG (ImpName name))
i)
      DModParam ModParam name
s -> forall a. PP a => a -> Doc
pp ModParam name
s
      DParamDecl Range
_ Signature name
ds -> forall name.
(Show name, PPName name) =>
Doc -> Signature name -> Doc
ppInterface Doc
"parameter" Signature name
ds
      DInterfaceConstraint Maybe Text
_ Located [Prop name]
ds ->
        Doc
"interface constraint" Doc -> Doc -> Doc
<+>
        case forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located [Prop name]
ds) of
          [Doc
x] -> Doc
x
          []  -> Doc
"()"
          [Doc]
xs  -> Int -> Doc -> Doc
nest Int
1 (Doc -> Doc
parens ([Doc] -> Doc
commaSepFill [Doc]
xs))

instance (Show name, PPName name) => PP (ParamDecl name) where
  ppPrec :: Int -> ParamDecl name -> Doc
ppPrec Int
_ ParamDecl name
pd =
    case ParamDecl name
pd of
      DParameterFun ParameterFun name
d -> forall a. PP a => a -> Doc
pp ParameterFun name
d
      DParameterType ParameterType name
d -> forall a. PP a => a -> Doc
pp ParameterType name
d
      DParameterDecl SigDecl name
d -> forall a. PP a => a -> Doc
pp SigDecl name
d
      DParameterConstraint [Located (Prop name)]
d ->
        Doc
"type constraint" Doc -> Doc -> Doc
<+> Doc -> Doc
parens ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => a -> Doc
pp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Located a -> a
thing) [Located (Prop name)]
d))

ppInterface :: (Show name, PPName name) => Doc -> Signature name -> Doc
ppInterface :: forall name.
(Show name, PPName name) =>
Doc -> Signature name -> Doc
ppInterface Doc
kw Signature name
sig = Doc
kw Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
indent Int
2 ([Doc] -> Doc
vcat ([Doc]
is forall a. [a] -> [a] -> [a]
++ [Doc]
ds))
    where
    is :: [Doc]
is = forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp (forall name. Signature name -> [Located (ImportG (ImpName name))]
sigImports Signature name
sig)
    cs :: [Doc]
cs = case forall name. Signature name -> [Located (Prop name)]
sigConstraints Signature name
sig of
           []  -> []
           [Located (Prop name)]
cs' -> [Doc
"type constraint" Doc -> Doc -> Doc
<+>
                       Doc -> Doc
parens ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => a -> Doc
pp forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Located a -> a
thing) [Located (Prop name)]
cs'))]
    ds :: [Doc]
ds = forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp (forall name. Signature name -> [ParameterType name]
sigTypeParams Signature name
sig)
      forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp (forall name. Signature name -> [SigDecl name]
sigDecls Signature name
sig)
      forall a. [a] -> [a] -> [a]
++ [Doc]
cs
      forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp (forall name. Signature name -> [ParameterFun name]
sigFunParams Signature name
sig)

instance (Show name, PPName name) => PP (SigDecl name) where
  ppPrec :: Int -> SigDecl name -> Doc
ppPrec Int
p SigDecl name
decl =
    case SigDecl name
decl of
      SigTySyn TySyn name
ts Maybe Text
_   -> forall a. PP a => Int -> a -> Doc
ppPrec Int
p TySyn name
ts
      SigPropSyn PropSyn name
ps Maybe Text
_ -> forall a. PP a => Int -> a -> Doc
ppPrec Int
p PropSyn name
ps


instance (Show name, PPName name) => PP (ModParam name) where
  ppPrec :: Int -> ModParam name -> Doc
ppPrec Int
_ ModParam name
mp = [Doc] -> Doc
vcat ( [Doc]
mbDoc
                  forall a. [a] -> [a] -> [a]
++ [ Doc
"import interface" Doc -> Doc -> Doc
<+>
                                    forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing (forall name. ModParam name -> Located (ImpName name)
mpSignature ModParam name
mp)) Doc -> Doc -> Doc
<+> Doc
mbAs ]
                  forall a. [a] -> [a] -> [a]
++ [Doc]
mbRen
                     )
    where
    mbDoc :: [Doc]
mbDoc = case forall name. ModParam name -> Maybe (Located Text)
mpDoc ModParam name
mp of
              Maybe (Located Text)
Nothing -> []
              Just Located Text
d  -> [forall a. PP a => a -> Doc
pp Located Text
d]
    mbAs :: Doc
mbAs  = case forall name. ModParam name -> Maybe ModName
mpAs ModParam name
mp of
              Maybe ModName
Nothing -> forall a. Monoid a => a
mempty
              Just ModName
d  -> Doc
"as" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp ModName
d
    mbRen :: [Doc]
mbRen
      | forall k a. Map k a -> Bool
Map.null (forall name. ModParam name -> Map name name
mpRenaming ModParam name
mp) = []
      | Bool
otherwise =
        [ Int -> Doc -> Doc
indent Int
2 forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vcat forall a b. (a -> b) -> a -> b
$ Doc
"/* Parameters"
                          forall a. a -> [a] -> [a]
: [ Doc
" *" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp name
x Doc -> Doc -> Doc
<+> Doc
"->" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp name
y
                            | (name
x,name
y) <- forall k a. Map k a -> [(k, a)]
Map.toList (forall name. ModParam name -> Map name name
mpRenaming ModParam name
mp) ]
                         forall a. [a] -> [a] -> [a]
++ [Doc
" */"] ]

instance (Show name, PPName name) => PP (PrimType name) where
  ppPrec :: Int -> PrimType name -> Doc
ppPrec Int
_ PrimType name
pt =
    Doc
"primitive" Doc -> Doc -> Doc
<+> Doc
"type" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall name. PrimType name -> Located name
primTName PrimType name
pt) Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall name. PrimType name -> Located Kind
primTKind PrimType name
pt)

instance (Show name, PPName name) => PP (ParameterType name) where
  ppPrec :: Int -> ParameterType name -> Doc
ppPrec Int
_ ParameterType name
a = FilePath -> Doc
text FilePath
"type" Doc -> Doc -> Doc
<+>
               forall a. PPName a => a -> Doc
ppPrefixName (forall name. ParameterType name -> Located name
ptName ParameterType name
a) Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall name. ParameterType name -> Kind
ptKind ParameterType name
a)

instance (Show name, PPName name) => PP (ParameterFun name) where
  ppPrec :: Int -> ParameterFun name -> Doc
ppPrec Int
_ ParameterFun name
a = forall a. PPName a => a -> Doc
ppPrefixName (forall name. ParameterFun name -> Located name
pfName ParameterFun name
a) Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":"
                  Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp (forall name. ParameterFun name -> Schema name
pfSchema ParameterFun name
a)


instance (Show name, PPName name) => PP (Decl name) where
  ppPrec :: Int -> Decl name -> Doc
ppPrec Int
n Decl name
decl =
    case Decl name
decl of
      DSignature [Located name]
xs Schema name
s -> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => Located a -> Doc
ppL [Located name]
xs) Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Schema name
s
      DPatBind Pattern name
p Expr name
e    -> forall a. PP a => a -> Doc
pp Pattern name
p Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"=" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e
      DBind Bind name
b         -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n Bind name
b
      DRec [Bind name]
bs         -> Int -> Doc -> Doc
nest Int
2 ([Doc] -> Doc
vcat (Doc
"recursive" forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
n) [Bind name]
bs))
      DFixity Fixity
f [Located name]
ns    -> forall name. PPName name => Fixity -> [Located name] -> Doc
ppFixity Fixity
f [Located name]
ns
      DPragma [Located name]
xs Pragma
p    -> forall name. PPName name => [Located name] -> Pragma -> Doc
ppPragma [Located name]
xs Pragma
p
      DType TySyn name
ts        -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n TySyn name
ts
      DProp PropSyn name
ps        -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n PropSyn name
ps
      DLocated Decl name
d Range
_    -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n Decl name
d

ppFixity :: PPName name => Fixity -> [Located name] -> Doc
ppFixity :: forall name. PPName name => Fixity -> [Located name] -> Doc
ppFixity (Fixity Assoc
LeftAssoc  Int
i) [Located name]
ns = FilePath -> Doc
text FilePath
"infixl" Doc -> Doc -> Doc
<+> Int -> Doc
int Int
i Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Located name]
ns)
ppFixity (Fixity Assoc
RightAssoc Int
i) [Located name]
ns = FilePath -> Doc
text FilePath
"infixr" Doc -> Doc -> Doc
<+> Int -> Doc
int Int
i Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Located name]
ns)
ppFixity (Fixity Assoc
NonAssoc   Int
i) [Located name]
ns = FilePath -> Doc
text FilePath
"infix"  Doc -> Doc -> Doc
<+> Int -> Doc
int Int
i Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Located name]
ns)

instance PPName name => PP (Newtype name) where
  ppPrec :: Int -> Newtype name -> Doc
ppPrec Int
_ Newtype name
nt = Int -> Doc -> Doc
nest Int
2 forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep
    [ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ [FilePath -> Doc
text FilePath
"newtype", forall a. PP a => Located a -> Doc
ppL (forall name. Newtype name -> Located name
nName Newtype name
nt)] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp (forall name. Newtype name -> [TParam name]
nParams Newtype name
nt) forall a. [a] -> [a] -> [a]
++ [Char -> Doc
char Char
'=']
    , [Doc] -> Doc
ppRecord (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => FilePath -> (Ident, (Range, a)) -> Doc
ppNamed' FilePath
":") (forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields (forall name. Newtype name -> Rec (Type name)
nBody Newtype name
nt)))
    ]

instance (PP mname) => PP (ImportG mname) where
  ppPrec :: Int -> ImportG mname -> Doc
ppPrec Int
_ ImportG mname
d = [Doc] -> Doc
vcat [ FilePath -> Doc
text FilePath
"import" Doc -> Doc -> Doc
<+> [Doc] -> Doc
sep ([forall a. PP a => a -> Doc
pp (forall mname. ImportG mname -> mname
iModule ImportG mname
d)] forall a. [a] -> [a] -> [a]
++ [Doc]
mbInst forall a. [a] -> [a] -> [a]
++
                                                      [Doc]
mbAs forall a. [a] -> [a] -> [a]
++ [Doc]
mbSpec)
                    , Int -> Doc -> Doc
indent Int
2 Doc
mbWhere
                    ]
    where
    mbAs :: [Doc]
mbAs   = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ ModName
name -> [FilePath -> Doc
text FilePath
"as" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp ModName
name]) (forall mname. ImportG mname -> Maybe ModName
iAs ImportG mname
d)
    mbSpec :: [Doc]
mbSpec = forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ImportSpec
x -> [forall a. PP a => a -> Doc
pp ImportSpec
x]) (forall mname. ImportG mname -> Maybe ImportSpec
iSpec ImportG mname
d)
    mbInst :: [Doc]
mbInst = case forall mname. ImportG mname -> Maybe (ModuleInstanceArgs PName)
iInst ImportG mname
d of
                Just (DefaultInstArg Located (ModuleInstanceArg PName)
x) -> [ Doc -> Doc
braces (forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located (ModuleInstanceArg PName)
x)) ]
                Just (NamedInstArgs [ModuleInstanceNamedArg PName]
xs) -> [ Doc -> Doc
braces ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [ModuleInstanceNamedArg PName]
xs)) ]
                Maybe (ModuleInstanceArgs PName)
_ -> []
    mbWhere :: Doc
mbWhere = case forall mname. ImportG mname -> Maybe (ModuleInstanceArgs PName)
iInst ImportG mname
d of
                Just (DefaultInstAnonArg [TopDecl PName]
ds) ->
                  Doc
"where" Doc -> Doc -> Doc
$$ [Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [TopDecl PName]
ds)
                Maybe (ModuleInstanceArgs PName)
_ -> forall a. Monoid a => a
mempty
 

instance PP name => PP (ImpName name) where
  ppPrec :: Int -> ImpName name -> Doc
ppPrec Int
_ ImpName name
nm =
    case ImpName name
nm of
      ImpTop ModName
x    -> forall a. PP a => a -> Doc
pp ModName
x
      ImpNested name
x -> Doc
"submodule" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp name
x

instance PP ImportSpec where
  ppPrec :: Int -> ImportSpec -> Doc
ppPrec Int
_ ImportSpec
s = case ImportSpec
s of
    Hiding [Ident]
names -> FilePath -> Doc
text FilePath
"hiding" Doc -> Doc -> Doc
<+> Doc -> Doc
parens ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Ident]
names))
    Only [Ident]
names   ->                   Doc -> Doc
parens ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Ident]
names))

-- TODO: come up with a good way of showing the export specification here
instance PP a => PP (TopLevel a) where
  ppPrec :: Int -> TopLevel a -> Doc
ppPrec Int
_ TopLevel a
tl = forall a. PP a => a -> Doc
pp (forall a. TopLevel a -> a
tlValue TopLevel a
tl)


instance PP Pragma where
  ppPrec :: Int -> Pragma -> Doc
ppPrec Int
_ (PragmaNote FilePath
x) = FilePath -> Doc
text FilePath
x
  ppPrec Int
_ Pragma
PragmaProperty = FilePath -> Doc
text FilePath
"property"

ppPragma :: PPName name => [Located name] -> Pragma -> Doc
ppPragma :: forall name. PPName name => [Located name] -> Pragma -> Doc
ppPragma [Located name]
xs Pragma
p =
  FilePath -> Doc
text FilePath
"/*" Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"pragma" Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => Located a -> Doc
ppL [Located name]
xs) Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Pragma
p
  Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"*/"

instance (Show name, PPName name) => PP (Bind name) where
  ppPrec :: Int -> Bind name -> Doc
ppPrec Int
_ Bind name
b = [Doc] -> Doc
vcat ([Doc]
sig forall a. [a] -> [a] -> [a]
++ [ forall name. PPName name => [Located name] -> Pragma -> Doc
ppPragma [Located name
f] Pragma
p | Pragma
p <- forall name. Bind name -> [Pragma]
bPragmas Bind name
b ] forall a. [a] -> [a] -> [a]
++
                     [Doc -> Int -> Doc -> Doc
hang (Doc
def Doc -> Doc -> Doc
<+> Doc
eq) Int
4 (forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing (forall name. Bind name -> Located (BindDef name)
bDef Bind name
b)))])
    where def :: Doc
def | forall name. Bind name -> Bool
bInfix Bind name
b  = Doc
lhsOp
              | Bool
otherwise = Doc
lhs
          f :: Located name
f = forall name. Bind name -> Located name
bName Bind name
b
          sig :: [Doc]
sig = case forall name. Bind name -> Maybe (Schema name)
bSignature Bind name
b of
                  Maybe (Schema name)
Nothing -> []
                  Just Schema name
s  -> [forall a. PP a => a -> Doc
pp (forall name. [Located name] -> Schema name -> Decl name
DSignature [Located name
f] Schema name
s)]
          eq :: Doc
eq  = if forall name. Bind name -> Bool
bMono Bind name
b then FilePath -> Doc
text FilePath
":=" else FilePath -> Doc
text FilePath
"="
          lhs :: Doc
lhs = [Doc] -> Doc
fsep (forall a. PP a => Located a -> Doc
ppL Located name
f forall a. a -> [a] -> [a]
: (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
3) (forall name. Bind name -> [Pattern name]
bParams Bind name
b)))

          lhsOp :: Doc
lhsOp = case forall name. Bind name -> [Pattern name]
bParams Bind name
b of
                    [Pattern name
x,Pattern name
y] -> forall a. PP a => a -> Doc
pp Pattern name
x Doc -> Doc -> Doc
<+> forall a. PP a => Located a -> Doc
ppL Located name
f Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Pattern name
y
                    [Pattern name]
xs -> Doc -> Doc
parens (Doc -> Doc
parens (forall a. PP a => Located a -> Doc
ppL Located name
f) Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
0) [Pattern name]
xs))
                    -- _     -> panic "AST" [ "Malformed infix operator", show b ]


instance (Show name, PPName name) => PP (BindDef name) where
  ppPrec :: Int -> BindDef name -> Doc
ppPrec Int
_ BindDef name
DPrim     = FilePath -> Doc
text FilePath
"<primitive>"
  ppPrec Int
_ BindDef name
DForeign  = FilePath -> Doc
text FilePath
"<foreign>"
  ppPrec Int
p (DExpr Expr name
e) = forall a. PP a => Int -> a -> Doc
ppPrec Int
p Expr name
e
  ppPrec Int
_p (DPropGuards [PropGuardCase name]
_guards) = FilePath -> Doc
text FilePath
"propguards"


instance PPName name => PP (TySyn name) where
  ppPrec :: Int -> TySyn name -> Doc
ppPrec Int
_ (TySyn Located name
x Maybe Fixity
_ [TParam name]
xs Type name
t) =
    Int -> Doc -> Doc
nest Int
2 forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep forall a b. (a -> b) -> a -> b
$
      [ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ [FilePath -> Doc
text FilePath
"type", forall a. PP a => Located a -> Doc
ppL Located name
x] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
1) [TParam name]
xs forall a. [a] -> [a] -> [a]
++ [FilePath -> Doc
text FilePath
"="]
      , forall a. PP a => a -> Doc
pp Type name
t
      ]

instance PPName name => PP (PropSyn name) where
  ppPrec :: Int -> PropSyn name -> Doc
ppPrec Int
_ (PropSyn Located name
x Maybe Fixity
_ [TParam name]
xs [Prop name]
ps) =
    Int -> Doc -> Doc
nest Int
2 forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep forall a b. (a -> b) -> a -> b
$
      [ [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ [FilePath -> Doc
text FilePath
"constraint", forall a. PP a => Located a -> Doc
ppL Located name
x] forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
1) [TParam name]
xs forall a. [a] -> [a] -> [a]
++ [FilePath -> Doc
text FilePath
"="]
      , Doc -> Doc
parens ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Prop name]
ps))
      ]

instance PP Literal where
  ppPrec :: Int -> Literal -> Doc
ppPrec Int
_ Literal
lit =
    case Literal
lit of
      ECNum Integer
n NumInfo
i     -> Integer -> NumInfo -> Doc
ppNumLit Integer
n NumInfo
i
      ECChar Char
c      -> FilePath -> Doc
text (forall a. Show a => a -> FilePath
show Char
c)
      ECFrac Rational
n FracInfo
i    -> Rational -> FracInfo -> Doc
ppFracLit Rational
n FracInfo
i
      ECString FilePath
s    -> FilePath -> Doc
text (forall a. Show a => a -> FilePath
show FilePath
s)

ppFracLit :: Rational -> FracInfo -> Doc
ppFracLit :: Rational -> FracInfo -> Doc
ppFracLit Rational
x FracInfo
i
  | forall a. Real a => a -> Rational
toRational Double
dbl forall a. Eq a => a -> a -> Bool
== Rational
x =
    case FracInfo
i of
      BinFrac Text
_ -> Doc
frac
      OctFrac Text
_ -> Doc
frac
      DecFrac Text
_ -> FilePath -> Doc
text (forall a. RealFloat a => a -> ShowS
showFloat Double
dbl FilePath
"")
      HexFrac Text
_ -> FilePath -> Doc
text (forall a. RealFloat a => a -> ShowS
showHFloat Double
dbl FilePath
"")
  | Bool
otherwise = Doc
frac
  where
  dbl :: Double
dbl = forall a. Fractional a => Rational -> a
fromRational Rational
x :: Double
  frac :: Doc
frac = Doc
"fraction`" Doc -> Doc -> Doc
<.> Doc -> Doc
braces
                      ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map Integer -> Doc
integer [ forall a. Ratio a -> a
numerator Rational
x, forall a. Ratio a -> a
denominator Rational
x ]))


ppNumLit :: Integer -> NumInfo -> Doc
ppNumLit :: Integer -> NumInfo -> Doc
ppNumLit Integer
n NumInfo
info =
  case NumInfo
info of
    DecLit Text
_   -> Integer -> Doc
integer Integer
n
    BinLit Text
_ Int
w -> Integer -> FilePath -> Int -> Doc
pad Integer
2  FilePath
"0b" Int
w
    OctLit Text
_ Int
w -> Integer -> FilePath -> Int -> Doc
pad Integer
8  FilePath
"0o" Int
w
    HexLit Text
_ Int
w -> Integer -> FilePath -> Int -> Doc
pad Integer
16 FilePath
"0x" Int
w
    PolyLit Int
w  -> FilePath -> Doc
text FilePath
"<|" Doc -> Doc -> Doc
<+> Int -> Doc
poly Int
w Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"|>"
  where
  pad :: Integer -> FilePath -> Int -> Doc
pad Integer
base FilePath
pref Int
w =
    let txt :: FilePath
txt = forall a. (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS
showIntAtBase Integer
base (FilePath
"0123456789abcdef" forall a. [a] -> Int -> a
!!) Integer
n FilePath
""
    in FilePath -> Doc
text FilePath
pref Doc -> Doc -> Doc
<.> FilePath -> Doc
text (forall a. Int -> a -> [a]
replicate (Int
w forall a. Num a => a -> a -> a
- forall (t :: * -> *) a. Foldable t => t a -> Int
length FilePath
txt) Char
'0') Doc -> Doc -> Doc
<.> FilePath -> Doc
text FilePath
txt

  poly :: Int -> Doc
poly Int
w = let ([Int]
res,Maybe Int
deg) = forall {t} {a}.
(Integral t, Num a, Bits t) =>
Maybe a -> [a] -> a -> t -> ([a], Maybe a)
bits forall a. Maybe a
Nothing [] Int
0 Integer
n
               z :: [Doc]
z | Int
w forall a. Eq a => a -> a -> Bool
== Int
0 = []
                 | Just Int
d <- Maybe Int
deg, Int
d forall a. Num a => a -> a -> a
+ Int
1 forall a. Eq a => a -> a -> Bool
== Int
w = []
                 | Bool
otherwise = [Int -> Doc
polyTerm0 (Int
wforall a. Num a => a -> a -> a
-Int
1)]
           in [Doc] -> Doc
fsep forall a b. (a -> b) -> a -> b
$ forall a. a -> [a] -> [a]
intersperse (FilePath -> Doc
text FilePath
"+") forall a b. (a -> b) -> a -> b
$ [Doc]
z forall a. [a] -> [a] -> [a]
++ forall a b. (a -> b) -> [a] -> [b]
map Int -> Doc
polyTerm [Int]
res

  polyTerm :: Int -> Doc
polyTerm Int
0 = FilePath -> Doc
text FilePath
"1"
  polyTerm Int
1 = FilePath -> Doc
text FilePath
"x"
  polyTerm Int
p = FilePath -> Doc
text FilePath
"x" Doc -> Doc -> Doc
<.> FilePath -> Doc
text FilePath
"^^" Doc -> Doc -> Doc
<.> Int -> Doc
int Int
p

  polyTerm0 :: Int -> Doc
polyTerm0 Int
0 = FilePath -> Doc
text FilePath
"0"
  polyTerm0 Int
p = FilePath -> Doc
text FilePath
"0" Doc -> Doc -> Doc
<.> FilePath -> Doc
text FilePath
"*" Doc -> Doc -> Doc
<.> Int -> Doc
polyTerm Int
p

  bits :: Maybe a -> [a] -> a -> t -> ([a], Maybe a)
bits Maybe a
d [a]
res a
p t
num
    | t
num forall a. Eq a => a -> a -> Bool
== t
0  = ([a]
res,Maybe a
d)
    | forall a. Integral a => a -> Bool
even t
num  = Maybe a -> [a] -> a -> t -> ([a], Maybe a)
bits Maybe a
d             [a]
res  (a
p forall a. Num a => a -> a -> a
+ a
1) (t
num forall a. Bits a => a -> Int -> a
`shiftR` Int
1)
    | Bool
otherwise = Maybe a -> [a] -> a -> t -> ([a], Maybe a)
bits (forall a. a -> Maybe a
Just a
p) (a
p forall a. a -> [a] -> [a]
: [a]
res) (a
p forall a. Num a => a -> a -> a
+ a
1) (t
num forall a. Bits a => a -> Int -> a
`shiftR` Int
1)

wrap :: Int -> Int -> Doc -> Doc
wrap :: Int -> Int -> Doc -> Doc
wrap Int
contextPrec Int
myPrec Doc
doc = Bool -> Doc -> Doc
optParens (Int
myPrec forall a. Ord a => a -> a -> Bool
< Int
contextPrec) Doc
doc

isEApp :: Expr n -> Maybe (Expr n, Expr n)
isEApp :: forall n. Expr n -> Maybe (Expr n, Expr n)
isEApp (ELocated Expr n
e Range
_)     = forall n. Expr n -> Maybe (Expr n, Expr n)
isEApp Expr n
e
isEApp (EApp Expr n
e1 Expr n
e2)       = forall a. a -> Maybe a
Just (Expr n
e1,Expr n
e2)
isEApp Expr n
_                  = forall a. Maybe a
Nothing

asEApps :: Expr n -> (Expr n, [Expr n])
asEApps :: forall n. Expr n -> (Expr n, [Expr n])
asEApps Expr n
expr = forall {n}. Expr n -> [Expr n] -> (Expr n, [Expr n])
go Expr n
expr []
    where go :: Expr n -> [Expr n] -> (Expr n, [Expr n])
go Expr n
e [Expr n]
es = case forall n. Expr n -> Maybe (Expr n, Expr n)
isEApp Expr n
e of
                      Maybe (Expr n, Expr n)
Nothing       -> (Expr n
e, [Expr n]
es)
                      Just (Expr n
e1, Expr n
e2) -> Expr n -> [Expr n] -> (Expr n, [Expr n])
go Expr n
e1 (Expr n
e2 forall a. a -> [a] -> [a]
: [Expr n]
es)

instance PPName name => PP (TypeInst name) where
  ppPrec :: Int -> TypeInst name -> Doc
ppPrec Int
_ (PosInst Type name
t)   = forall a. PP a => a -> Doc
pp Type name
t
  ppPrec Int
_ (NamedInst Named (Type name)
x) = forall a. PP a => FilePath -> Named a -> Doc
ppNamed FilePath
"=" Named (Type name)
x

{- Precedences:
0: lambda, if, where, type annotation
2: infix expression   (separate precedence table)
3: application, prefix expressions
-}
instance (Show name, PPName name) => PP (Expr name) where
  -- Wrap if top level operator in expression is less than `n`
  ppPrec :: Int -> Expr name -> Doc
ppPrec Int
n Expr name
expr =
    case Expr name
expr of

      -- atoms
      EVar name
x        -> forall a. PPName a => a -> Doc
ppPrefixName name
x
      ELit Literal
x        -> forall a. PP a => a -> Doc
pp Literal
x

      EGenerate Expr name
x   -> Int -> Int -> Doc -> Doc
wrap Int
n Int
3 (FilePath -> Doc
text FilePath
"generate" Doc -> Doc -> Doc
<+> forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
x)

      ETuple [Expr name]
es     -> Doc -> Doc
parens ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Expr name]
es))
      ERecord Rec (Expr name)
fs    -> Doc -> Doc
braces ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => FilePath -> (Ident, (Range, a)) -> Doc
ppNamed' FilePath
"=") (forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields Rec (Expr name)
fs)))
      EList [Expr name]
es      -> Doc -> Doc
brackets ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Expr name]
es))
      EFromTo Type name
e1 Maybe (Type name)
e2 Type name
e3 Maybe (Type name)
t1 -> Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Type name
e1 Doc -> Doc -> Doc
<.> Doc
step Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
".." Doc -> Doc -> Doc
<+> Doc
end)
        where step :: Doc
step = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\Type name
e -> Doc
comma Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
e) Maybe (Type name)
e2
              end :: Doc
end = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. PP a => a -> Doc
pp Type name
e3) (\Type name
t -> forall a. PP a => a -> Doc
pp Type name
e3 Doc -> Doc -> Doc
<+> Doc
colon Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
t) Maybe (Type name)
t1
      EFromToBy Bool
isStrict Type name
e1 Type name
e2 Type name
e3 Maybe (Type name)
t1 -> Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Type name
e1 Doc -> Doc -> Doc
<+> Doc
dots Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
e2 Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"by" Doc -> Doc -> Doc
<+> Doc
end)
        where end :: Doc
end = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. PP a => a -> Doc
pp Type name
e3) (\Type name
t -> forall a. PP a => a -> Doc
pp Type name
e3 Doc -> Doc -> Doc
<+> Doc
colon Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
t) Maybe (Type name)
t1
              dots :: Doc
dots | Bool
isStrict  = FilePath -> Doc
text FilePath
".. <"
                   | Bool
otherwise = FilePath -> Doc
text FilePath
".."
      EFromToDownBy Bool
isStrict Type name
e1 Type name
e2 Type name
e3 Maybe (Type name)
t1 -> Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Type name
e1 Doc -> Doc -> Doc
<+> Doc
dots Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
e2 Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"down by" Doc -> Doc -> Doc
<+> Doc
end)
        where end :: Doc
end = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. PP a => a -> Doc
pp Type name
e3) (\Type name
t -> forall a. PP a => a -> Doc
pp Type name
e3 Doc -> Doc -> Doc
<+> Doc
colon Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
t) Maybe (Type name)
t1
              dots :: Doc
dots | Bool
isStrict  = FilePath -> Doc
text FilePath
".. >"
                   | Bool
otherwise = FilePath -> Doc
text FilePath
".."
      EFromToLessThan Type name
e1 Type name
e2 Maybe (Type name)
t1 -> Doc -> Doc
brackets (Doc
strt Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
".. <" Doc -> Doc -> Doc
<+> Doc
end)
        where strt :: Doc
strt = forall b a. b -> (a -> b) -> Maybe a -> b
maybe (forall a. PP a => a -> Doc
pp Type name
e1) (\Type name
t -> forall a. PP a => a -> Doc
pp Type name
e1 Doc -> Doc -> Doc
<+> Doc
colon Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
t) Maybe (Type name)
t1
              end :: Doc
end  = forall a. PP a => a -> Doc
pp Type name
e2
      EInfFrom Expr name
e1 Maybe (Expr name)
e2 -> Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Expr name
e1 Doc -> Doc -> Doc
<.> Doc
step Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"...")
        where step :: Doc
step = forall b a. b -> (a -> b) -> Maybe a -> b
maybe forall a. Monoid a => a
mempty (\Expr name
e -> Doc
comma Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e) Maybe (Expr name)
e2
      EComp Expr name
e [[Match name]]
mss   -> Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Expr name
e forall a. Semigroup a => a -> a -> a
<> Doc -> Doc
align ([Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall {a}. PP a => [a] -> Doc
arm [[Match name]]
mss)))
        where arm :: [a] -> Doc
arm [a]
ms = FilePath -> Doc
text FilePath
" |" Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [a]
ms)
      EUpd Maybe (Expr name)
mb [UpdField name]
fs    -> Doc -> Doc
braces (Doc
hd Doc -> Doc -> Doc
<+> Doc
"|" Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [UpdField name]
fs))
        where hd :: Doc
hd = forall b a. b -> (a -> b) -> Maybe a -> b
maybe Doc
"_" forall a. PP a => a -> Doc
pp Maybe (Expr name)
mb

      ETypeVal Type name
t    -> FilePath -> Doc
text FilePath
"`" Doc -> Doc -> Doc
<.> forall a. PP a => Int -> a -> Doc
ppPrec Int
5 Type name
t     -- XXX
      EAppT Expr name
e [TypeInst name]
ts    -> forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e Doc -> Doc -> Doc
<.> FilePath -> Doc
text FilePath
"`" Doc -> Doc -> Doc
<.> Doc -> Doc
braces ([Doc] -> Doc
commaSep (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [TypeInst name]
ts))
      ESel    Expr name
e Selector
l   -> forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e Doc -> Doc -> Doc
<.> FilePath -> Doc
text FilePath
"." Doc -> Doc -> Doc
<.> forall a. PP a => a -> Doc
pp Selector
l

      -- low prec
      EFun FunDesc name
_ [Pattern name]
xs Expr name
e   -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 ((FilePath -> Doc
text FilePath
"\\" Doc -> Doc -> Doc
<.> [Doc] -> Doc
hsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
3) [Pattern name]
xs)) Doc -> Doc -> Doc
<+>
                                 FilePath -> Doc
text FilePath
"->" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e)

      EIf Expr name
e1 Expr name
e2 Expr name
e3  -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep [ FilePath -> Doc
text FilePath
"if"   Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e1
                                      , FilePath -> Doc
text FilePath
"then" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e2
                                      , FilePath -> Doc
text FilePath
"else" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e3 ]

      ETyped Expr name
e Type name
t    -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 (forall a. PP a => Int -> a -> Doc
ppPrec Int
2 Expr name
e Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
t)

      EWhere  Expr name
e [Decl name]
ds  -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 forall a b. (a -> b) -> a -> b
$ Doc -> Doc
align forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vsep
                         [ forall a. PP a => a -> Doc
pp Expr name
e
                         , Doc -> Int -> Doc -> Doc
hang Doc
"where" Int
2 ([Doc] -> Doc
vcat (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Decl name]
ds))
                         ]

      -- infix applications
      Expr name
_ | Just Infix name (Expr name)
ifix <- forall {op}. PPName op => Expr op -> Maybe (Infix op (Expr op))
isInfix Expr name
expr ->
              Bool -> Doc -> Doc
optParens (Int
n forall a. Ord a => a -> a -> Bool
> Int
2)
              forall a b. (a -> b) -> a -> b
$ forall thing op.
(PP thing, PP op) =>
Int -> (thing -> Maybe (Infix op thing)) -> Infix op thing -> Doc
ppInfix Int
2 forall {op}. PPName op => Expr op -> Maybe (Infix op (Expr op))
isInfix Infix name (Expr name)
ifix

      EApp Expr name
_ Expr name
_      -> let (Expr name
e, [Expr name]
es) = forall n. Expr n -> (Expr n, [Expr n])
asEApps Expr name
expr in
                       Int -> Int -> Doc -> Doc
wrap Int
n Int
3 (forall a. PP a => Int -> a -> Doc
ppPrec Int
3 Expr name
e Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
4) [Expr name]
es))

      ELocated Expr name
e Range
_  -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n Expr name
e

      ESplit Expr name
e      -> Int -> Int -> Doc -> Doc
wrap Int
n Int
3 (FilePath -> Doc
text FilePath
"splitAt" Doc -> Doc -> Doc
<+> forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e)

      EParens Expr name
e -> Doc -> Doc
parens (forall a. PP a => a -> Doc
pp Expr name
e)

      -- NOTE: these don't produce correctly parenthesized expressions without
      -- explicit EParens nodes when necessary, since we don't check the actual
      -- fixities of the operators.
      EInfix Expr name
e1 Located name
op Fixity
_ Expr name
e2 -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 (forall a. PP a => a -> Doc
pp Expr name
e1 Doc -> Doc -> Doc
<+> forall a. PPName a => a -> Doc
ppInfixName (forall a. Located a -> a
thing Located name
op) Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e2)

      EPrefix PrefixOp
op Expr name
e  -> Int -> Int -> Doc -> Doc
wrap Int
n Int
3 (FilePath -> Doc
text (forall {a}. IsString a => PrefixOp -> a
prefixText PrefixOp
op) Doc -> Doc -> Doc
<.> forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e)
   where
   isInfix :: Expr op -> Maybe (Infix op (Expr op))
isInfix (EApp (EApp (EVar op
ieOp) Expr op
ieLeft) Expr op
ieRight) = do
     Fixity
ieFixity <- forall a. PPName a => a -> Maybe Fixity
ppNameFixity op
ieOp
     forall (m :: * -> *) a. Monad m => a -> m a
return Infix { op
Fixity
Expr op
ieFixity :: Fixity
ieRight :: Expr op
ieLeft :: Expr op
ieOp :: op
ieFixity :: Fixity
ieRight :: Expr op
ieLeft :: Expr op
ieOp :: op
.. }
   isInfix Expr op
_ = forall a. Maybe a
Nothing
   prefixText :: PrefixOp -> a
prefixText PrefixOp
PrefixNeg        = a
"-"
   prefixText PrefixOp
PrefixComplement = a
"~"

instance (Show name, PPName name) => PP (UpdField name) where
  ppPrec :: Int -> UpdField name -> Doc
ppPrec Int
_ (UpdField UpdHow
h [Located Selector]
xs Expr name
e) = [Selector] -> Doc
ppNestedSels (forall a b. (a -> b) -> [a] -> [b]
map forall a. Located a -> a
thing [Located Selector]
xs) Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp UpdHow
h Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e

instance PP UpdHow where
  ppPrec :: Int -> UpdHow -> Doc
ppPrec Int
_ UpdHow
h = case UpdHow
h of
                 UpdHow
UpdSet -> Doc
"="
                 UpdHow
UpdFun -> Doc
"->"

instance PPName name => PP (Pattern name) where
  ppPrec :: Int -> Pattern name -> Doc
ppPrec Int
n Pattern name
pat =
    case Pattern name
pat of
      PVar Located name
x        -> forall a. PP a => a -> Doc
pp (forall a. Located a -> a
thing Located name
x)
      Pattern name
PWild         -> Char -> Doc
char Char
'_'
      PTuple [Pattern name]
ps     -> [Doc] -> Doc
ppTuple (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Pattern name]
ps)
      PRecord Rec (Pattern name)
fs    -> [Doc] -> Doc
ppRecord (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => FilePath -> (Ident, (Range, a)) -> Doc
ppNamed' FilePath
"=") (forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields Rec (Pattern name)
fs))
      PList [Pattern name]
ps      -> [Doc] -> Doc
ppList (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Pattern name]
ps)
      PTyped Pattern name
p Type name
t    -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 (forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Pattern name
p  Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Type name
t)
      PSplit Pattern name
p1 Pattern name
p2  -> Int -> Int -> Doc -> Doc
wrap Int
n Int
1 (forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Pattern name
p1 Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"#" Doc -> Doc -> Doc
<+> forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Pattern name
p2)
      PLocated Pattern name
p Range
_  -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n Pattern name
p

instance (Show name, PPName name) => PP (Match name) where
  ppPrec :: Int -> Match name -> Doc
ppPrec Int
_ (Match Pattern name
p Expr name
e)  = forall a. PP a => a -> Doc
pp Pattern name
p Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"<-" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Expr name
e
  ppPrec Int
_ (MatchLet Bind name
b) = forall a. PP a => a -> Doc
pp Bind name
b


instance PPName name => PP (Schema name) where
  ppPrec :: Int -> Schema name -> Doc
ppPrec Int
_ (Forall [TParam name]
xs [Prop name]
ps Type name
t Maybe Range
_) = [Doc] -> Doc
sep ([Doc]
vars forall a. [a] -> [a] -> [a]
++ [Doc]
preds forall a. [a] -> [a] -> [a]
++ [forall a. PP a => a -> Doc
pp Type name
t])
    where vars :: [Doc]
vars = case [TParam name]
xs of
                   [] -> []
                   [TParam name]
_  -> [Int -> Doc -> Doc
nest Int
1 (Doc -> Doc
braces ([Doc] -> Doc
commaSepFill (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [TParam name]
xs)))]
          preds :: [Doc]
preds = case [Prop name]
ps of
                    [] -> []
                    [Prop name]
_  -> [Int -> Doc -> Doc
nest Int
1 (Doc -> Doc
parens ([Doc] -> Doc
commaSepFill (forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Prop name]
ps))) Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"=>"]

instance PP Kind where
  ppPrec :: Int -> Kind -> Doc
ppPrec Int
_ Kind
KType  = FilePath -> Doc
text FilePath
"*"
  ppPrec Int
_ Kind
KNum   = FilePath -> Doc
text FilePath
"#"
  ppPrec Int
_ Kind
KProp  = FilePath -> Doc
text FilePath
"@"
  ppPrec Int
n (KFun Kind
k1 Kind
k2) = Int -> Int -> Doc -> Doc
wrap Int
n Int
1 (forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Kind
k1 Doc -> Doc -> Doc
<+> Doc
"->" Doc -> Doc -> Doc
<+> forall a. PP a => Int -> a -> Doc
ppPrec Int
0 Kind
k2)

-- | "Conversational" printing of kinds (e.g., to use in error messages)
cppKind :: Kind -> Doc
cppKind :: Kind -> Doc
cppKind Kind
KType     = FilePath -> Doc
text FilePath
"a value type"
cppKind Kind
KNum      = FilePath -> Doc
text FilePath
"a numeric type"
cppKind Kind
KProp     = FilePath -> Doc
text FilePath
"a constraint type"
cppKind (KFun {}) = FilePath -> Doc
text FilePath
"a type-constructor type"

instance PPName name => PP (TParam name) where
  ppPrec :: Int -> TParam name -> Doc
ppPrec Int
n (TParam name
p Maybe Kind
Nothing Maybe Range
_)   = forall a. PP a => Int -> a -> Doc
ppPrec Int
n name
p
  ppPrec Int
n (TParam name
p (Just Kind
k) Maybe Range
_)  = Int -> Int -> Doc -> Doc
wrap Int
n Int
1 (forall a. PP a => a -> Doc
pp name
p Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Kind
k)

-- 4: atomic type expression
-- 3: [_]t or application
-- 2: infix type
-- 1: function type
instance PPName name => PP (Type name) where
  ppPrec :: Int -> Type name -> Doc
ppPrec Int
n Type name
ty =
    case Type name
ty of
      Type name
TWild          -> FilePath -> Doc
text FilePath
"_"
      TTuple [Type name]
ts      -> Doc -> Doc
parens forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
commaSep forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. PP a => a -> Doc
pp [Type name]
ts
      TTyApp [Named (Type name)]
fs      -> Doc -> Doc
braces forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
commaSep forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => FilePath -> Named a -> Doc
ppNamed FilePath
" = ") [Named (Type name)]
fs
      TRecord Rec (Type name)
fs     -> Doc -> Doc
braces forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
commaSep forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => FilePath -> (Ident, (Range, a)) -> Doc
ppNamed' FilePath
":") (forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields Rec (Type name)
fs)
      Type name
TBit           -> FilePath -> Doc
text FilePath
"Bit"
      TNum Integer
x         -> Integer -> Doc
integer Integer
x
      TChar Char
x        -> FilePath -> Doc
text (forall a. Show a => a -> FilePath
show Char
x)
      TSeq Type name
t1 Type name
TBit   -> Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Type name
t1)
      TSeq Type name
t1 Type name
t2     -> Bool -> Doc -> Doc
optParens (Int
n forall a. Ord a => a -> a -> Bool
> Int
3)
                      forall a b. (a -> b) -> a -> b
$ Doc -> Doc
brackets (forall a. PP a => a -> Doc
pp Type name
t1) Doc -> Doc -> Doc
<.> forall a. PP a => Int -> a -> Doc
ppPrec Int
3 Type name
t2

      TUser name
f []     -> forall a. PPName a => a -> Doc
ppPrefixName name
f

      TUser name
f [Type name]
ts     -> Bool -> Doc -> Doc
optParens (Int
n forall a. Ord a => a -> a -> Bool
> Int
3)
                      forall a b. (a -> b) -> a -> b
$ forall a. PPName a => a -> Doc
ppPrefixName name
f Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep (forall a b. (a -> b) -> [a] -> [b]
map (forall a. PP a => Int -> a -> Doc
ppPrec Int
4) [Type name]
ts)

      TFun Type name
t1 Type name
t2     -> Bool -> Doc -> Doc
optParens (Int
n forall a. Ord a => a -> a -> Bool
> Int
1)
                      forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep [forall a. PP a => Int -> a -> Doc
ppPrec Int
2 Type name
t1 Doc -> Doc -> Doc
<+> FilePath -> Doc
text FilePath
"->", forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Type name
t2]

      TLocated Type name
t Range
_   -> forall a. PP a => Int -> a -> Doc
ppPrec Int
n Type name
t

      TParens Type name
t Maybe Kind
mb   -> Doc -> Doc
parens
                          case Maybe Kind
mb of
                            Maybe Kind
Nothing -> forall a. PP a => a -> Doc
pp Type name
t
                            Just Kind
k  -> forall a. PP a => a -> Doc
pp Type name
t Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> forall a. PP a => a -> Doc
pp Kind
k

      TInfix Type name
t1 Located name
o Fixity
_ Type name
t2 -> Bool -> Doc -> Doc
optParens (Int
n forall a. Ord a => a -> a -> Bool
> Int
2)
                        forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep [forall a. PP a => Int -> a -> Doc
ppPrec Int
2 Type name
t1 Doc -> Doc -> Doc
<+> forall a. PPName a => a -> Doc
ppInfixName Located name
o, forall a. PP a => Int -> a -> Doc
ppPrec Int
3 Type name
t2]


instance PPName name => PP (Prop name) where
  ppPrec :: Int -> Prop name -> Doc
ppPrec Int
n (CType Type name
t) = forall a. PP a => Int -> a -> Doc
ppPrec Int
n Type name
t

instance PPName name => PP [Prop name] where
  ppPrec :: Int -> [Prop name] -> Doc
ppPrec Int
n [Prop name]
props = Doc -> Doc
parens forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Doc] -> Doc
commaSep forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a. PP a => Int -> a -> Doc
ppPrec Int
n) forall a b. (a -> b) -> a -> b
$ [Prop name]
props

--------------------------------------------------------------------------------
-- Drop all position information, so equality reflects program structure

class NoPos t where
  noPos :: t -> t

-- WARNING: This does not call `noPos` on the `thing` inside
instance NoPos (Located t) where
  noPos :: Located t -> Located t
noPos Located t
x = Located t
x { srcRange :: Range
srcRange = Range
rng }
    where rng :: Range
rng = Range { from :: Position
from = Int -> Int -> Position
Position Int
0 Int
0, to :: Position
to = Int -> Int -> Position
Position Int
0 Int
0, source :: FilePath
source = FilePath
"" }

instance NoPos t => NoPos (Named t) where
  noPos :: Named t -> Named t
noPos Named t
t = Named { name :: Located Ident
name = forall t. NoPos t => t -> t
noPos (forall a. Named a -> Located Ident
name Named t
t), value :: t
value = forall t. NoPos t => t -> t
noPos (forall a. Named a -> a
value Named t
t) }

instance NoPos Range where
  noPos :: Range -> Range
noPos Range
_ = Range { from :: Position
from = Int -> Int -> Position
Position Int
0 Int
0, to :: Position
to = Int -> Int -> Position
Position Int
0 Int
0, source :: FilePath
source = FilePath
"" }

instance NoPos t => NoPos [t]       where noPos :: [t] -> [t]
noPos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall t. NoPos t => t -> t
noPos
instance NoPos t => NoPos (Maybe t) where noPos :: Maybe t -> Maybe t
noPos = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall t. NoPos t => t -> t
noPos
instance (NoPos a, NoPos b) => NoPos (a,b) where
  noPos :: (a, b) -> (a, b)
noPos (a
a,b
b) = (forall t. NoPos t => t -> t
noPos a
a, forall t. NoPos t => t -> t
noPos b
b)

instance NoPos (Program name) where
  noPos :: Program name -> Program name
noPos (Program [TopDecl name]
x) = forall name. [TopDecl name] -> Program name
Program (forall t. NoPos t => t -> t
noPos [TopDecl name]
x)

instance NoPos (ModuleG mname name) where
  noPos :: ModuleG mname name -> ModuleG mname name
noPos ModuleG mname name
m = Module { mName :: Located mname
mName      = forall mname name. ModuleG mname name -> Located mname
mName ModuleG mname name
m
                   , mDef :: ModuleDefinition name
mDef       = forall t. NoPos t => t -> t
noPos (forall mname name. ModuleG mname name -> ModuleDefinition name
mDef ModuleG mname name
m)
                   }

instance NoPos (ModuleDefinition name) where
  noPos :: ModuleDefinition name -> ModuleDefinition name
noPos ModuleDefinition name
m =
    case ModuleDefinition name
m of
      NormalModule [TopDecl name]
ds         -> forall name. [TopDecl name] -> ModuleDefinition name
NormalModule (forall t. NoPos t => t -> t
noPos [TopDecl name]
ds)
      FunctorInstance Located (ImpName name)
f ModuleInstanceArgs name
as ModuleInstance name
ds -> forall name.
Located (ImpName name)
-> ModuleInstanceArgs name
-> ModuleInstance name
-> ModuleDefinition name
FunctorInstance (forall t. NoPos t => t -> t
noPos Located (ImpName name)
f) (forall t. NoPos t => t -> t
noPos ModuleInstanceArgs name
as) ModuleInstance name
ds
      InterfaceModule Signature name
s       -> forall name. Signature name -> ModuleDefinition name
InterfaceModule (forall t. NoPos t => t -> t
noPos Signature name
s)

instance NoPos (ModuleInstanceArgs name) where
  noPos :: ModuleInstanceArgs name -> ModuleInstanceArgs name
noPos ModuleInstanceArgs name
as =
    case ModuleInstanceArgs name
as of
      DefaultInstArg Located (ModuleInstanceArg name)
a      -> forall name.
Located (ModuleInstanceArg name) -> ModuleInstanceArgs name
DefaultInstArg (forall t. NoPos t => t -> t
noPos Located (ModuleInstanceArg name)
a)
      DefaultInstAnonArg [TopDecl name]
ds -> forall name. [TopDecl name] -> ModuleInstanceArgs name
DefaultInstAnonArg (forall t. NoPos t => t -> t
noPos [TopDecl name]
ds)
      NamedInstArgs [ModuleInstanceNamedArg name]
xs      -> forall name.
[ModuleInstanceNamedArg name] -> ModuleInstanceArgs name
NamedInstArgs (forall t. NoPos t => t -> t
noPos [ModuleInstanceNamedArg name]
xs)

instance NoPos (ModuleInstanceNamedArg name) where
  noPos :: ModuleInstanceNamedArg name -> ModuleInstanceNamedArg name
noPos (ModuleInstanceNamedArg Located Ident
x Located (ModuleInstanceArg name)
y) =
    forall name.
Located Ident
-> Located (ModuleInstanceArg name) -> ModuleInstanceNamedArg name
ModuleInstanceNamedArg (forall t. NoPos t => t -> t
noPos Located Ident
x) (forall t. NoPos t => t -> t
noPos Located (ModuleInstanceArg name)
y)

instance NoPos (NestedModule name) where
  noPos :: NestedModule name -> NestedModule name
noPos (NestedModule ModuleG name name
m) = forall name. ModuleG name name -> NestedModule name
NestedModule (forall t. NoPos t => t -> t
noPos ModuleG name name
m)

instance NoPos (TopDecl name) where
  noPos :: TopDecl name -> TopDecl name
noPos TopDecl name
decl =
    case TopDecl name
decl of
      Decl    TopLevel (Decl name)
x   -> forall name. TopLevel (Decl name) -> TopDecl name
Decl     (forall t. NoPos t => t -> t
noPos TopLevel (Decl name)
x)
      DPrimType TopLevel (PrimType name)
t -> forall name. TopLevel (PrimType name) -> TopDecl name
DPrimType (forall t. NoPos t => t -> t
noPos TopLevel (PrimType name)
t)
      TDNewtype TopLevel (Newtype name)
n -> forall name. TopLevel (Newtype name) -> TopDecl name
TDNewtype(forall t. NoPos t => t -> t
noPos TopLevel (Newtype name)
n)
      Include Located FilePath
x   -> forall name. Located FilePath -> TopDecl name
Include  (forall t. NoPos t => t -> t
noPos Located FilePath
x)
      DModule TopLevel (NestedModule name)
d -> forall name. TopLevel (NestedModule name) -> TopDecl name
DModule (forall t. NoPos t => t -> t
noPos TopLevel (NestedModule name)
d)
      DImport Located (ImportG (ImpName name))
d -> forall name. Located (ImportG (ImpName name)) -> TopDecl name
DImport (forall t. NoPos t => t -> t
noPos Located (ImportG (ImpName name))
d)
      DModParam ModParam name
d -> forall name. ModParam name -> TopDecl name
DModParam (forall t. NoPos t => t -> t
noPos ModParam name
d)
      DParamDecl Range
_ Signature name
ds -> forall name. Range -> Signature name -> TopDecl name
DParamDecl Range
rng (forall t. NoPos t => t -> t
noPos Signature name
ds)
        where rng :: Range
rng = Range { from :: Position
from = Int -> Int -> Position
Position Int
0 Int
0, to :: Position
to = Int -> Int -> Position
Position Int
0 Int
0, source :: FilePath
source = FilePath
"" }
      DInterfaceConstraint Maybe Text
d Located [Prop name]
ds -> forall name. Maybe Text -> Located [Prop name] -> TopDecl name
DInterfaceConstraint Maybe Text
d (forall t. NoPos t => t -> t
noPos (forall t. NoPos t => t -> t
noPos forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Located [Prop name]
ds))

instance NoPos (ParamDecl name) where
  noPos :: ParamDecl name -> ParamDecl name
noPos ParamDecl name
pd =
    case ParamDecl name
pd of
      DParameterFun ParameterFun name
d  -> forall name. ParameterFun name -> ParamDecl name
DParameterFun (forall t. NoPos t => t -> t
noPos ParameterFun name
d)
      DParameterType ParameterType name
d -> forall name. ParameterType name -> ParamDecl name
DParameterType (forall t. NoPos t => t -> t
noPos ParameterType name
d)
      DParameterDecl SigDecl name
d -> forall name. SigDecl name -> ParamDecl name
DParameterDecl (forall t. NoPos t => t -> t
noPos SigDecl name
d)
      DParameterConstraint [Located (Prop name)]
d -> forall name. [Located (Prop name)] -> ParamDecl name
DParameterConstraint (forall t. NoPos t => t -> t
noPos [Located (Prop name)]
d)

instance NoPos (Signature name) where
  noPos :: Signature name -> Signature name
noPos Signature name
sig = Signature { sigImports :: [Located (ImportG (ImpName name))]
sigImports = forall name. Signature name -> [Located (ImportG (ImpName name))]
sigImports Signature name
sig
                        , sigTypeParams :: [ParameterType name]
sigTypeParams = forall a b. (a -> b) -> [a] -> [b]
map forall t. NoPos t => t -> t
noPos (forall name. Signature name -> [ParameterType name]
sigTypeParams Signature name
sig)
                        , sigDecls :: [SigDecl name]
sigDecls = forall a b. (a -> b) -> [a] -> [b]
map forall t. NoPos t => t -> t
noPos (forall name. Signature name -> [SigDecl name]
sigDecls Signature name
sig)
                        , sigConstraints :: [Located (Prop name)]
sigConstraints = forall a b. (a -> b) -> [a] -> [b]
map forall t. NoPos t => t -> t
noPos (forall name. Signature name -> [Located (Prop name)]
sigConstraints Signature name
sig)
                        , sigFunParams :: [ParameterFun name]
sigFunParams = forall a b. (a -> b) -> [a] -> [b]
map forall t. NoPos t => t -> t
noPos (forall name. Signature name -> [ParameterFun name]
sigFunParams Signature name
sig)
                        }

instance NoPos (SigDecl name) where
  noPos :: SigDecl name -> SigDecl name
noPos SigDecl name
decl =
    case SigDecl name
decl of
      SigTySyn TySyn name
ts Maybe Text
mb   -> forall name. TySyn name -> Maybe Text -> SigDecl name
SigTySyn (forall t. NoPos t => t -> t
noPos TySyn name
ts) Maybe Text
mb
      SigPropSyn PropSyn name
ps Maybe Text
mb -> forall name. PropSyn name -> Maybe Text -> SigDecl name
SigPropSyn (forall t. NoPos t => t -> t
noPos PropSyn name
ps) Maybe Text
mb

instance NoPos (ModParam name) where
  noPos :: ModParam name -> ModParam name
noPos ModParam name
mp = ModParam { mpSignature :: Located (ImpName name)
mpSignature = forall t. NoPos t => t -> t
noPos (forall name. ModParam name -> Located (ImpName name)
mpSignature ModParam name
mp)
                      , mpAs :: Maybe ModName
mpAs        = forall name. ModParam name -> Maybe ModName
mpAs ModParam name
mp
                      , mpName :: Ident
mpName      = forall name. ModParam name -> Ident
mpName ModParam name
mp
                      , mpDoc :: Maybe (Located Text)
mpDoc       = forall t. NoPos t => t -> t
noPos forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall name. ModParam name -> Maybe (Located Text)
mpDoc ModParam name
mp
                      , mpRenaming :: Map name name
mpRenaming  = forall name. ModParam name -> Map name name
mpRenaming ModParam name
mp
                      }

instance NoPos (PrimType name) where
  noPos :: PrimType name -> PrimType name
noPos PrimType name
x = PrimType name
x

instance NoPos (ParameterType name) where
  noPos :: ParameterType name -> ParameterType name
noPos ParameterType name
a = ParameterType name
a

instance NoPos (ParameterFun x) where
  noPos :: ParameterFun x -> ParameterFun x
noPos ParameterFun x
x = ParameterFun x
x { pfSchema :: Schema x
pfSchema = forall t. NoPos t => t -> t
noPos (forall name. ParameterFun name -> Schema name
pfSchema ParameterFun x
x) }

instance NoPos a => NoPos (TopLevel a) where
  noPos :: TopLevel a -> TopLevel a
noPos TopLevel a
tl = TopLevel a
tl { tlValue :: a
tlValue = forall t. NoPos t => t -> t
noPos (forall a. TopLevel a -> a
tlValue TopLevel a
tl) }

instance NoPos (Decl name) where
  noPos :: Decl name -> Decl name
noPos Decl name
decl =
    case Decl name
decl of
      DSignature [Located name]
x Schema name
y   -> forall name. [Located name] -> Schema name -> Decl name
DSignature (forall t. NoPos t => t -> t
noPos [Located name]
x) (forall t. NoPos t => t -> t
noPos Schema name
y)
      DPragma    [Located name]
x Pragma
y   -> forall name. [Located name] -> Pragma -> Decl name
DPragma    (forall t. NoPos t => t -> t
noPos [Located name]
x) (forall t. NoPos t => t -> t
noPos Pragma
y)
      DPatBind   Pattern name
x Expr name
y   -> forall name. Pattern name -> Expr name -> Decl name
DPatBind   (forall t. NoPos t => t -> t
noPos Pattern name
x) (forall t. NoPos t => t -> t
noPos Expr name
y)
      DFixity Fixity
f [Located name]
ns     -> forall name. Fixity -> [Located name] -> Decl name
DFixity Fixity
f (forall t. NoPos t => t -> t
noPos [Located name]
ns)
      DBind      Bind name
x     -> forall name. Bind name -> Decl name
DBind      (forall t. NoPos t => t -> t
noPos Bind name
x)
      DRec       [Bind name]
bs    -> forall name. [Bind name] -> Decl name
DRec       (forall a b. (a -> b) -> [a] -> [b]
map forall t. NoPos t => t -> t
noPos [Bind name]
bs)
      DType      TySyn name
x     -> forall name. TySyn name -> Decl name
DType      (forall t. NoPos t => t -> t
noPos TySyn name
x)
      DProp      PropSyn name
x     -> forall name. PropSyn name -> Decl name
DProp      (forall t. NoPos t => t -> t
noPos PropSyn name
x)
      DLocated   Decl name
x Range
_   -> forall t. NoPos t => t -> t
noPos Decl name
x

instance NoPos (Newtype name) where
  noPos :: Newtype name -> Newtype name
noPos Newtype name
n = Newtype { nName :: Located name
nName     = forall t. NoPos t => t -> t
noPos (forall name. Newtype name -> Located name
nName Newtype name
n)
                    , nParams :: [TParam name]
nParams   = forall name. Newtype name -> [TParam name]
nParams Newtype name
n
                    , nConName :: name
nConName  = forall name. Newtype name -> name
nConName Newtype name
n
                    , nBody :: Rec (Type name)
nBody     = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall t. NoPos t => t -> t
noPos (forall name. Newtype name -> Rec (Type name)
nBody Newtype name
n)
                    }

instance NoPos (Bind name) where
  noPos :: Bind name -> Bind name
noPos Bind name
x = Bind { bName :: Located name
bName      = forall t. NoPos t => t -> t
noPos (forall name. Bind name -> Located name
bName      Bind name
x)
                 , bParams :: [Pattern name]
bParams    = forall t. NoPos t => t -> t
noPos (forall name. Bind name -> [Pattern name]
bParams    Bind name
x)
                 , bDef :: Located (BindDef name)
bDef       = forall t. NoPos t => t -> t
noPos (forall name. Bind name -> Located (BindDef name)
bDef       Bind name
x)
                 , bSignature :: Maybe (Schema name)
bSignature = forall t. NoPos t => t -> t
noPos (forall name. Bind name -> Maybe (Schema name)
bSignature Bind name
x)
                 , bInfix :: Bool
bInfix     = forall name. Bind name -> Bool
bInfix Bind name
x
                 , bFixity :: Maybe Fixity
bFixity    = forall name. Bind name -> Maybe Fixity
bFixity Bind name
x
                 , bPragmas :: [Pragma]
bPragmas   = forall t. NoPos t => t -> t
noPos (forall name. Bind name -> [Pragma]
bPragmas   Bind name
x)
                 , bMono :: Bool
bMono      = forall name. Bind name -> Bool
bMono Bind name
x
                 , bDoc :: Maybe Text
bDoc       = forall name. Bind name -> Maybe Text
bDoc Bind name
x
                 , bExport :: ExportType
bExport    = forall name. Bind name -> ExportType
bExport Bind name
x
                 }

instance NoPos Pragma where
  noPos :: Pragma -> Pragma
noPos p :: Pragma
p@(PragmaNote {})   = Pragma
p
  noPos p :: Pragma
p@(Pragma
PragmaProperty)  = Pragma
p



instance NoPos (TySyn name) where
  noPos :: TySyn name -> TySyn name
noPos (TySyn Located name
x Maybe Fixity
f [TParam name]
y Type name
z) = forall n.
Located n -> Maybe Fixity -> [TParam n] -> Type n -> TySyn n
TySyn (forall t. NoPos t => t -> t
noPos Located name
x) Maybe Fixity
f (forall t. NoPos t => t -> t
noPos [TParam name]
y) (forall t. NoPos t => t -> t
noPos Type name
z)

instance NoPos (PropSyn name) where
  noPos :: PropSyn name -> PropSyn name
noPos (PropSyn Located name
x Maybe Fixity
f [TParam name]
y [Prop name]
z) = forall n.
Located n -> Maybe Fixity -> [TParam n] -> [Prop n] -> PropSyn n
PropSyn (forall t. NoPos t => t -> t
noPos Located name
x) Maybe Fixity
f (forall t. NoPos t => t -> t
noPos [TParam name]
y) (forall t. NoPos t => t -> t
noPos [Prop name]
z)

instance NoPos (Expr name) where
  noPos :: Expr name -> Expr name
noPos Expr name
expr =
    case Expr name
expr of
      EVar name
x          -> forall n. n -> Expr n
EVar     name
x
      ELit Literal
x          -> forall n. Literal -> Expr n
ELit     Literal
x
      EGenerate Expr name
x     -> forall n. Expr n -> Expr n
EGenerate (forall t. NoPos t => t -> t
noPos Expr name
x)
      ETuple [Expr name]
x        -> forall n. [Expr n] -> Expr n
ETuple   (forall t. NoPos t => t -> t
noPos [Expr name]
x)
      ERecord Rec (Expr name)
x       -> forall n. Rec (Expr n) -> Expr n
ERecord  (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall t. NoPos t => t -> t
noPos Rec (Expr name)
x)
      ESel Expr name
x Selector
y        -> forall n. Expr n -> Selector -> Expr n
ESel     (forall t. NoPos t => t -> t
noPos Expr name
x) Selector
y
      EUpd Maybe (Expr name)
x [UpdField name]
y        -> forall n. Maybe (Expr n) -> [UpdField n] -> Expr n
EUpd     (forall t. NoPos t => t -> t
noPos Maybe (Expr name)
x) (forall t. NoPos t => t -> t
noPos [UpdField name]
y)
      EList [Expr name]
x         -> forall n. [Expr n] -> Expr n
EList    (forall t. NoPos t => t -> t
noPos [Expr name]
x)
      EFromTo Type name
x Maybe (Type name)
y Type name
z Maybe (Type name)
t -> forall n.
Type n -> Maybe (Type n) -> Type n -> Maybe (Type n) -> Expr n
EFromTo  (forall t. NoPos t => t -> t
noPos Type name
x) (forall t. NoPos t => t -> t
noPos Maybe (Type name)
y) (forall t. NoPos t => t -> t
noPos Type name
z) (forall t. NoPos t => t -> t
noPos Maybe (Type name)
t)
      EFromToBy Bool
isStrict Type name
x Type name
y Type name
z Maybe (Type name)
t
                      -> forall n.
Bool -> Type n -> Type n -> Type n -> Maybe (Type n) -> Expr n
EFromToBy Bool
isStrict (forall t. NoPos t => t -> t
noPos Type name
x) (forall t. NoPos t => t -> t
noPos Type name
y) (forall t. NoPos t => t -> t
noPos Type name
z) (forall t. NoPos t => t -> t
noPos Maybe (Type name)
t)
      EFromToDownBy Bool
isStrict Type name
x Type name
y Type name
z Maybe (Type name)
t
                      -> forall n.
Bool -> Type n -> Type n -> Type n -> Maybe (Type n) -> Expr n
EFromToDownBy Bool
isStrict (forall t. NoPos t => t -> t
noPos Type name
x) (forall t. NoPos t => t -> t
noPos Type name
y) (forall t. NoPos t => t -> t
noPos Type name
z) (forall t. NoPos t => t -> t
noPos Maybe (Type name)
t)
      EFromToLessThan Type name
x Type name
y Maybe (Type name)
t -> forall n. Type n -> Type n -> Maybe (Type n) -> Expr n
EFromToLessThan (forall t. NoPos t => t -> t
noPos Type name
x) (forall t. NoPos t => t -> t
noPos Type name
y) (forall t. NoPos t => t -> t
noPos Maybe (Type name)
t)
      EInfFrom Expr name
x Maybe (Expr name)
y    -> forall n. Expr n -> Maybe (Expr n) -> Expr n
EInfFrom (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos Maybe (Expr name)
y)
      EComp Expr name
x [[Match name]]
y       -> forall n. Expr n -> [[Match n]] -> Expr n
EComp    (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos [[Match name]]
y)
      EApp  Expr name
x Expr name
y       -> forall n. Expr n -> Expr n -> Expr n
EApp     (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos Expr name
y)
      EAppT Expr name
x [TypeInst name]
y       -> forall n. Expr n -> [TypeInst n] -> Expr n
EAppT    (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos [TypeInst name]
y)
      EIf   Expr name
x Expr name
y Expr name
z     -> forall n. Expr n -> Expr n -> Expr n -> Expr n
EIf      (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos Expr name
y) (forall t. NoPos t => t -> t
noPos Expr name
z)
      EWhere Expr name
x [Decl name]
y      -> forall n. Expr n -> [Decl n] -> Expr n
EWhere   (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos [Decl name]
y)
      ETyped Expr name
x Type name
y      -> forall n. Expr n -> Type n -> Expr n
ETyped   (forall t. NoPos t => t -> t
noPos Expr name
x) (forall t. NoPos t => t -> t
noPos Type name
y)
      ETypeVal Type name
x      -> forall n. Type n -> Expr n
ETypeVal (forall t. NoPos t => t -> t
noPos Type name
x)
      EFun FunDesc name
dsc [Pattern name]
x Expr name
y    -> forall n. FunDesc n -> [Pattern n] -> Expr n -> Expr n
EFun FunDesc name
dsc (forall t. NoPos t => t -> t
noPos [Pattern name]
x) (forall t. NoPos t => t -> t
noPos Expr name
y)
      ELocated Expr name
x Range
_    -> forall t. NoPos t => t -> t
noPos Expr name
x

      ESplit Expr name
x        -> forall n. Expr n -> Expr n
ESplit (forall t. NoPos t => t -> t
noPos Expr name
x)
      EParens Expr name
e       -> forall n. Expr n -> Expr n
EParens (forall t. NoPos t => t -> t
noPos Expr name
e)
      EInfix Expr name
x Located name
y Fixity
f Expr name
z  -> forall n. Expr n -> Located n -> Fixity -> Expr n -> Expr n
EInfix (forall t. NoPos t => t -> t
noPos Expr name
x) Located name
y Fixity
f (forall t. NoPos t => t -> t
noPos Expr name
z)
      EPrefix PrefixOp
op Expr name
x    -> forall n. PrefixOp -> Expr n -> Expr n
EPrefix PrefixOp
op (forall t. NoPos t => t -> t
noPos Expr name
x)

instance NoPos (UpdField name) where
  noPos :: UpdField name -> UpdField name
noPos (UpdField UpdHow
h [Located Selector]
xs Expr name
e) = forall n. UpdHow -> [Located Selector] -> Expr n -> UpdField n
UpdField UpdHow
h [Located Selector]
xs (forall t. NoPos t => t -> t
noPos Expr name
e)

instance NoPos (TypeInst name) where
  noPos :: TypeInst name -> TypeInst name
noPos (PosInst Type name
ts)   = forall name. Type name -> TypeInst name
PosInst (forall t. NoPos t => t -> t
noPos Type name
ts)
  noPos (NamedInst Named (Type name)
fs) = forall name. Named (Type name) -> TypeInst name
NamedInst (forall t. NoPos t => t -> t
noPos Named (Type name)
fs)

instance NoPos (Match name) where
  noPos :: Match name -> Match name
noPos (Match Pattern name
x Expr name
y)  = forall name. Pattern name -> Expr name -> Match name
Match (forall t. NoPos t => t -> t
noPos Pattern name
x) (forall t. NoPos t => t -> t
noPos Expr name
y)
  noPos (MatchLet Bind name
b) = forall name. Bind name -> Match name
MatchLet (forall t. NoPos t => t -> t
noPos Bind name
b)

instance NoPos (Pattern name) where
  noPos :: Pattern name -> Pattern name
noPos Pattern name
pat =
    case Pattern name
pat of
      PVar Located name
x       -> forall n. Located n -> Pattern n
PVar    (forall t. NoPos t => t -> t
noPos Located name
x)
      Pattern name
PWild        -> forall n. Pattern n
PWild
      PTuple [Pattern name]
x     -> forall n. [Pattern n] -> Pattern n
PTuple  (forall t. NoPos t => t -> t
noPos [Pattern name]
x)
      PRecord Rec (Pattern name)
x    -> forall n. Rec (Pattern n) -> Pattern n
PRecord (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall t. NoPos t => t -> t
noPos Rec (Pattern name)
x)
      PList [Pattern name]
x      -> forall n. [Pattern n] -> Pattern n
PList   (forall t. NoPos t => t -> t
noPos [Pattern name]
x)
      PTyped Pattern name
x Type name
y   -> forall n. Pattern n -> Type n -> Pattern n
PTyped  (forall t. NoPos t => t -> t
noPos Pattern name
x) (forall t. NoPos t => t -> t
noPos Type name
y)
      PSplit Pattern name
x Pattern name
y   -> forall n. Pattern n -> Pattern n -> Pattern n
PSplit  (forall t. NoPos t => t -> t
noPos Pattern name
x) (forall t. NoPos t => t -> t
noPos Pattern name
y)
      PLocated Pattern name
x Range
_ -> forall t. NoPos t => t -> t
noPos Pattern name
x

instance NoPos (Schema name) where
  noPos :: Schema name -> Schema name
noPos (Forall [TParam name]
x [Prop name]
y Type name
z Maybe Range
_) = forall n.
[TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
Forall (forall t. NoPos t => t -> t
noPos [TParam name]
x) (forall t. NoPos t => t -> t
noPos [Prop name]
y) (forall t. NoPos t => t -> t
noPos Type name
z) forall a. Maybe a
Nothing

instance NoPos (TParam name) where
  noPos :: TParam name -> TParam name
noPos (TParam name
x Maybe Kind
y Maybe Range
_)  = forall n. n -> Maybe Kind -> Maybe Range -> TParam n
TParam name
x Maybe Kind
y forall a. Maybe a
Nothing

instance NoPos (Type name) where
  noPos :: Type name -> Type name
noPos Type name
ty =
    case Type name
ty of
      Type name
TWild         -> forall n. Type n
TWild
      TUser name
x [Type name]
y     -> forall n. n -> [Type n] -> Type n
TUser    name
x         (forall t. NoPos t => t -> t
noPos [Type name]
y)
      TTyApp [Named (Type name)]
x      -> forall n. [Named (Type n)] -> Type n
TTyApp   (forall t. NoPos t => t -> t
noPos [Named (Type name)]
x)
      TRecord Rec (Type name)
x     -> forall n. Rec (Type n) -> Type n
TRecord  (forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap forall t. NoPos t => t -> t
noPos Rec (Type name)
x)
      TTuple [Type name]
x      -> forall n. [Type n] -> Type n
TTuple   (forall t. NoPos t => t -> t
noPos [Type name]
x)
      TFun Type name
x Type name
y      -> forall n. Type n -> Type n -> Type n
TFun     (forall t. NoPos t => t -> t
noPos Type name
x) (forall t. NoPos t => t -> t
noPos Type name
y)
      TSeq Type name
x Type name
y      -> forall n. Type n -> Type n -> Type n
TSeq     (forall t. NoPos t => t -> t
noPos Type name
x) (forall t. NoPos t => t -> t
noPos Type name
y)
      Type name
TBit          -> forall n. Type n
TBit
      TNum Integer
n        -> forall n. Integer -> Type n
TNum Integer
n
      TChar Char
n       -> forall n. Char -> Type n
TChar Char
n
      TLocated Type name
x Range
_  -> forall t. NoPos t => t -> t
noPos Type name
x
      TParens Type name
x Maybe Kind
k   -> forall n. Type n -> Maybe Kind -> Type n
TParens (forall t. NoPos t => t -> t
noPos Type name
x) Maybe Kind
k
      TInfix Type name
x Located name
y Fixity
f Type name
z-> forall n. Type n -> Located n -> Fixity -> Type n -> Type n
TInfix (forall t. NoPos t => t -> t
noPos Type name
x) Located name
y Fixity
f (forall t. NoPos t => t -> t
noPos Type name
z)

instance NoPos (Prop name) where
  noPos :: Prop name -> Prop name
noPos (CType Type name
t) = forall n. Type n -> Prop n
CType (forall t. NoPos t => t -> t
noPos Type name
t)