-- |
-- 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 #-}
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(..)
  , mImports
  , mSubmoduleImports
  , Program(..)
  , TopDecl(..)
  , Decl(..)
  , Fixity(..), defaultFixity
  , FixityCmp(..), compareFixity
  , TySyn(..)
  , PropSyn(..)
  , Bind(..)
  , BindDef(..), LBindDef
  , Pragma(..)
  , ExportType(..)
  , TopLevel(..)
  , Import, ImportG(..), ImportSpec(..), ImpName(..)
  , Newtype(..)
  , PrimType(..)
  , ParameterType(..)
  , ParameterFun(..)
  , NestedModule(..)

    -- * Interactive
  , ReplInput(..)

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

    -- * 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.List(intersperse)
import           Data.Bits(shiftR)
import           Data.Maybe (catMaybes)
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
[Program name] -> ShowS
Program name -> String
(Int -> Program name -> ShowS)
-> (Program name -> String)
-> ([Program name] -> ShowS)
-> Show (Program name)
forall name. Show name => Int -> Program name -> ShowS
forall name. Show name => [Program name] -> ShowS
forall name. Show name => Program name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Program name] -> ShowS
$cshowList :: forall name. Show name => [Program name] -> ShowS
show :: Program name -> String
$cshow :: forall name. Show name => Program name -> String
showsPrec :: Int -> Program name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Program name -> ShowS
Show)

-- | A parsed module.
data ModuleG mname name = Module
  { ModuleG mname name -> Located mname
mName     :: Located mname              -- ^ Name of the module
  , ModuleG mname name -> Maybe (Located ModName)
mInstance :: !(Maybe (Located ModName)) -- ^ Functor to instantiate
                                            -- (if this is a functor instnaces)
  -- , mImports  :: [Located Import]           -- ^ Imports for the module
  , ModuleG mname name -> [TopDecl name]
mDecls    :: [TopDecl name]             -- ^ Declartions for the module
  } deriving (Int -> ModuleG mname name -> ShowS
[ModuleG mname name] -> ShowS
ModuleG mname name -> String
(Int -> ModuleG mname name -> ShowS)
-> (ModuleG mname name -> String)
-> ([ModuleG mname name] -> ShowS)
-> Show (ModuleG mname name)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([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 -> String
showList :: [ModuleG mname name] -> ShowS
$cshowList :: forall mname name.
(Show mname, Show name) =>
[ModuleG mname name] -> ShowS
show :: ModuleG mname name -> String
$cshow :: forall mname name.
(Show mname, Show name) =>
ModuleG mname name -> String
showsPrec :: Int -> ModuleG mname name -> ShowS
$cshowsPrec :: forall mname name.
(Show mname, Show name) =>
Int -> ModuleG mname name -> ShowS
Show, (forall x. ModuleG mname name -> Rep (ModuleG mname name) x)
-> (forall x. Rep (ModuleG mname name) x -> ModuleG mname name)
-> Generic (ModuleG mname name)
forall x. Rep (ModuleG mname name) x -> ModuleG mname name
forall x. ModuleG mname name -> Rep (ModuleG mname name) x
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, ModuleG mname name -> ()
(ModuleG mname name -> ()) -> NFData (ModuleG mname name)
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)

mImports :: ModuleG mname name -> [ Located Import ]
mImports :: ModuleG mname name -> [Located Import]
mImports ModuleG mname name
m =
  [ Located (ImportG (ImpName name))
li { thing :: Import
thing = ImportG (ImpName name)
i { iModule :: ModName
iModule = ModName
n } }
  | DImport Located (ImportG (ImpName name))
li <- ModuleG mname name -> [TopDecl name]
forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m
  , let i :: ImportG (ImpName name)
i = Located (ImportG (ImpName name)) -> ImportG (ImpName name)
forall a. Located a -> a
thing Located (ImportG (ImpName name))
li
  , ImpTop ModName
n  <- [ImportG (ImpName name) -> ImpName name
forall mname. ImportG mname -> mname
iModule ImportG (ImpName name)
i]
  ]

mSubmoduleImports :: ModuleG mname name -> [ Located (ImportG name) ]
mSubmoduleImports :: ModuleG mname name -> [Located (ImportG name)]
mSubmoduleImports ModuleG mname name
m =
  [ Located (ImportG (ImpName name))
li { thing :: ImportG name
thing = ImportG (ImpName name)
i { iModule :: name
iModule = name
n } }
  | DImport Located (ImportG (ImpName name))
li <- ModuleG mname name -> [TopDecl name]
forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m
  , let i :: ImportG (ImpName name)
i = Located (ImportG (ImpName name)) -> ImportG (ImpName name)
forall a. Located a -> a
thing Located (ImportG (ImpName name))
li
  , ImpNested name
n  <- [ImportG (ImpName name) -> ImpName name
forall mname. ImportG mname -> mname
iModule ImportG (ImpName name)
i]
  ]



type Module = ModuleG ModName


newtype NestedModule name = NestedModule (ModuleG name name)
  deriving (Int -> NestedModule name -> ShowS
[NestedModule name] -> ShowS
NestedModule name -> String
(Int -> NestedModule name -> ShowS)
-> (NestedModule name -> String)
-> ([NestedModule name] -> ShowS)
-> Show (NestedModule name)
forall name. Show name => Int -> NestedModule name -> ShowS
forall name. Show name => [NestedModule name] -> ShowS
forall name. Show name => NestedModule name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [NestedModule name] -> ShowS
$cshowList :: forall name. Show name => [NestedModule name] -> ShowS
show :: NestedModule name -> String
$cshow :: forall name. Show name => NestedModule name -> String
showsPrec :: Int -> NestedModule name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> NestedModule name -> ShowS
Show,(forall x. NestedModule name -> Rep (NestedModule name) x)
-> (forall x. Rep (NestedModule name) x -> NestedModule name)
-> Generic (NestedModule name)
forall x. Rep (NestedModule name) x -> NestedModule name
forall x. NestedModule name -> Rep (NestedModule name) x
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,NestedModule name -> ()
(NestedModule name -> ()) -> NFData (NestedModule name)
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 :: Module name -> Range
modRange Module name
m = [Range] -> Range
rCombs ([Range] -> Range) -> [Range] -> Range
forall a b. (a -> b) -> a -> b
$ [Maybe Range] -> [Range]
forall a. [Maybe a] -> [a]
catMaybes
    [ Located ModName -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Module name -> Located ModName
forall mname name. ModuleG mname name -> Located mname
mName Module name
m)
    , [Located Import] -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Module name -> [Located Import]
forall mname name. ModuleG mname name -> [Located Import]
mImports Module name
m)
    , [TopDecl name] -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Module name -> [TopDecl name]
forall mname name. ModuleG mname name -> [TopDecl name]
mDecls Module name
m)
    , Range -> Maybe Range
forall a. a -> Maybe a
Just (Range :: Position -> Position -> String -> Range
Range { from :: Position
from = Position
start, to :: Position
to = Position
start, source :: String
source = String
"" })
    ]


data TopDecl name =
    Decl (TopLevel (Decl name))
  | DPrimType (TopLevel (PrimType name))
  | TDNewtype (TopLevel (Newtype name)) -- ^ @newtype T as = t
  | Include (Located FilePath)          -- ^ @include File@
  | DParameterType (ParameterType name) -- ^ @parameter type T : #@
  | DParameterConstraint [Located (Prop name)]
                                        -- ^ @parameter type constraint (fin T)@
  | DParameterFun  (ParameterFun name)  -- ^ @parameter someVal : [256]@
  | DModule (TopLevel (NestedModule name))  -- ^ Nested module
  | DImport (Located (ImportG (ImpName name)))  -- ^ An import declaration
                    deriving (Int -> TopDecl name -> ShowS
[TopDecl name] -> ShowS
TopDecl name -> String
(Int -> TopDecl name -> ShowS)
-> (TopDecl name -> String)
-> ([TopDecl name] -> ShowS)
-> Show (TopDecl name)
forall name. Show name => Int -> TopDecl name -> ShowS
forall name. Show name => [TopDecl name] -> ShowS
forall name. Show name => TopDecl name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TopDecl name] -> ShowS
$cshowList :: forall name. Show name => [TopDecl name] -> ShowS
show :: TopDecl name -> String
$cshow :: forall name. Show name => TopDecl name -> String
showsPrec :: Int -> TopDecl name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> TopDecl name -> ShowS
Show, (forall x. TopDecl name -> Rep (TopDecl name) x)
-> (forall x. Rep (TopDecl name) x -> TopDecl name)
-> Generic (TopDecl name)
forall x. Rep (TopDecl name) x -> TopDecl name
forall x. TopDecl name -> Rep (TopDecl name) x
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, TopDecl name -> ()
(TopDecl name -> ()) -> NFData (TopDecl name)
forall name. NFData name => TopDecl name -> ()
forall a. (a -> ()) -> NFData a
rnf :: TopDecl name -> ()
$crnf :: forall name. NFData name => TopDecl name -> ()
NFData)

data ImpName name =
    ImpTop    ModName
  | ImpNested name
    deriving (Int -> ImpName name -> ShowS
[ImpName name] -> ShowS
ImpName name -> String
(Int -> ImpName name -> ShowS)
-> (ImpName name -> String)
-> ([ImpName name] -> ShowS)
-> Show (ImpName name)
forall name. Show name => Int -> ImpName name -> ShowS
forall name. Show name => [ImpName name] -> ShowS
forall name. Show name => ImpName name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImpName name] -> ShowS
$cshowList :: forall name. Show name => [ImpName name] -> ShowS
show :: ImpName name -> String
$cshow :: forall name. Show name => ImpName name -> String
showsPrec :: Int -> ImpName name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ImpName name -> ShowS
Show, (forall x. ImpName name -> Rep (ImpName name) x)
-> (forall x. Rep (ImpName name) x -> ImpName name)
-> Generic (ImpName name)
forall x. Rep (ImpName name) x -> ImpName name
forall x. ImpName name -> Rep (ImpName name) x
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, ImpName name -> ()
(ImpName name -> ()) -> NFData (ImpName name)
forall name. NFData name => ImpName name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ImpName name -> ()
$crnf :: forall name. NFData name => ImpName name -> ()
NFData)

data Decl name = DSignature [Located name] (Schema name)
               | DFixity !Fixity [Located name]
               | DPragma [Located name] Pragma
               | DBind (Bind name)
               | DRec [Bind name]
                 -- ^ A group of recursive bindings, introduced by the renamer.
               | DPatBind (Pattern name) (Expr name)
               | DType (TySyn name)
               | DProp (PropSyn name)
               | DLocated (Decl name) Range
                 deriving (Decl name -> Decl name -> Bool
(Decl name -> Decl name -> Bool)
-> (Decl name -> Decl name -> Bool) -> Eq (Decl name)
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
[Decl name] -> ShowS
Decl name -> String
(Int -> Decl name -> ShowS)
-> (Decl name -> String)
-> ([Decl name] -> ShowS)
-> Show (Decl name)
forall name. Show name => Int -> Decl name -> ShowS
forall name. Show name => [Decl name] -> ShowS
forall name. Show name => Decl name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Decl name] -> ShowS
$cshowList :: forall name. Show name => [Decl name] -> ShowS
show :: Decl name -> String
$cshow :: forall name. Show name => Decl name -> String
showsPrec :: Int -> Decl name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Decl name -> ShowS
Show, (forall x. Decl name -> Rep (Decl name) x)
-> (forall x. Rep (Decl name) x -> Decl name)
-> Generic (Decl name)
forall x. Rep (Decl name) x -> Decl name
forall x. Decl name -> Rep (Decl name) x
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, Decl name -> ()
(Decl name -> ()) -> NFData (Decl name)
forall name. NFData name => Decl name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Decl name -> ()
$crnf :: forall name. NFData name => Decl name -> ()
NFData, a -> Decl b -> Decl a
(a -> b) -> Decl a -> Decl b
(forall a b. (a -> b) -> Decl a -> Decl b)
-> (forall a b. a -> Decl b -> Decl a) -> Functor Decl
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
<$ :: a -> Decl b -> Decl a
$c<$ :: forall a b. a -> Decl b -> Decl a
fmap :: (a -> b) -> Decl a -> Decl b
$cfmap :: forall a b. (a -> b) -> Decl a -> Decl b
Functor)


-- | A type parameter
data ParameterType name = ParameterType
  { ParameterType name -> Located name
ptName    :: Located name     -- ^ name of type parameter
  , ParameterType name -> Kind
ptKind    :: Kind             -- ^ kind of parameter
  , ParameterType name -> Maybe Text
ptDoc     :: Maybe Text       -- ^ optional documentation
  , ParameterType name -> Maybe Fixity
ptFixity  :: Maybe Fixity     -- ^ info for infix use
  , ParameterType name -> Int
ptNumber  :: !Int             -- ^ number of the parameter
  } deriving (ParameterType name -> ParameterType name -> Bool
(ParameterType name -> ParameterType name -> Bool)
-> (ParameterType name -> ParameterType name -> Bool)
-> Eq (ParameterType name)
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
[ParameterType name] -> ShowS
ParameterType name -> String
(Int -> ParameterType name -> ShowS)
-> (ParameterType name -> String)
-> ([ParameterType name] -> ShowS)
-> Show (ParameterType name)
forall name. Show name => Int -> ParameterType name -> ShowS
forall name. Show name => [ParameterType name] -> ShowS
forall name. Show name => ParameterType name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParameterType name] -> ShowS
$cshowList :: forall name. Show name => [ParameterType name] -> ShowS
show :: ParameterType name -> String
$cshow :: forall name. Show name => ParameterType name -> String
showsPrec :: Int -> ParameterType name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ParameterType name -> ShowS
Show,(forall x. ParameterType name -> Rep (ParameterType name) x)
-> (forall x. Rep (ParameterType name) x -> ParameterType name)
-> Generic (ParameterType name)
forall x. Rep (ParameterType name) x -> ParameterType name
forall x. ParameterType name -> Rep (ParameterType name) x
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,ParameterType name -> ()
(ParameterType name -> ()) -> NFData (ParameterType name)
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
data ParameterFun name = ParameterFun
  { ParameterFun name -> Located name
pfName   :: Located name      -- ^ name of value parameter
  , ParameterFun name -> Schema name
pfSchema :: Schema name       -- ^ schema for parameter
  , ParameterFun name -> Maybe Text
pfDoc    :: Maybe Text        -- ^ optional documentation
  , ParameterFun name -> Maybe Fixity
pfFixity :: Maybe Fixity      -- ^ info for infix use
  } deriving (ParameterFun name -> ParameterFun name -> Bool
(ParameterFun name -> ParameterFun name -> Bool)
-> (ParameterFun name -> ParameterFun name -> Bool)
-> Eq (ParameterFun name)
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
[ParameterFun name] -> ShowS
ParameterFun name -> String
(Int -> ParameterFun name -> ShowS)
-> (ParameterFun name -> String)
-> ([ParameterFun name] -> ShowS)
-> Show (ParameterFun name)
forall name. Show name => Int -> ParameterFun name -> ShowS
forall name. Show name => [ParameterFun name] -> ShowS
forall name. Show name => ParameterFun name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ParameterFun name] -> ShowS
$cshowList :: forall name. Show name => [ParameterFun name] -> ShowS
show :: ParameterFun name -> String
$cshow :: forall name. Show name => ParameterFun name -> String
showsPrec :: Int -> ParameterFun name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> ParameterFun name -> ShowS
Show,(forall x. ParameterFun name -> Rep (ParameterFun name) x)
-> (forall x. Rep (ParameterFun name) x -> ParameterFun name)
-> Generic (ParameterFun name)
forall x. Rep (ParameterFun name) x -> ParameterFun name
forall x. ParameterFun name -> Rep (ParameterFun name) x
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,ParameterFun name -> ()
(ParameterFun name -> ()) -> NFData (ParameterFun name)
forall name. NFData name => ParameterFun name -> ()
forall a. (a -> ()) -> NFData a
rnf :: ParameterFun name -> ()
$crnf :: forall name. NFData name => ParameterFun name -> ()
NFData)


-- | An import declaration.
data ImportG mname = Import
  { ImportG mname -> mname
iModule    :: !mname
  , ImportG mname -> Maybe ModName
iAs        :: Maybe ModName
  , ImportG mname -> Maybe ImportSpec
iSpec      :: Maybe ImportSpec
  } deriving (ImportG mname -> ImportG mname -> Bool
(ImportG mname -> ImportG mname -> Bool)
-> (ImportG mname -> ImportG mname -> Bool) -> Eq (ImportG mname)
forall mname. Eq mname => ImportG mname -> ImportG mname -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ImportG mname -> ImportG mname -> Bool
$c/= :: forall mname. Eq mname => ImportG mname -> ImportG mname -> Bool
== :: ImportG mname -> ImportG mname -> Bool
$c== :: forall mname. Eq mname => ImportG mname -> ImportG mname -> Bool
Eq, Int -> ImportG mname -> ShowS
[ImportG mname] -> ShowS
ImportG mname -> String
(Int -> ImportG mname -> ShowS)
-> (ImportG mname -> String)
-> ([ImportG mname] -> ShowS)
-> Show (ImportG mname)
forall mname. Show mname => Int -> ImportG mname -> ShowS
forall mname. Show mname => [ImportG mname] -> ShowS
forall mname. Show mname => ImportG mname -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportG mname] -> ShowS
$cshowList :: forall mname. Show mname => [ImportG mname] -> ShowS
show :: ImportG mname -> String
$cshow :: forall mname. Show mname => ImportG mname -> String
showsPrec :: Int -> ImportG mname -> ShowS
$cshowsPrec :: forall mname. Show mname => Int -> ImportG mname -> ShowS
Show, (forall x. ImportG mname -> Rep (ImportG mname) x)
-> (forall x. Rep (ImportG mname) x -> ImportG mname)
-> Generic (ImportG mname)
forall x. Rep (ImportG mname) x -> ImportG mname
forall x. ImportG mname -> Rep (ImportG mname) x
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, ImportG mname -> ()
(ImportG mname -> ()) -> NFData (ImportG mname)
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
(ImportSpec -> ImportSpec -> Bool)
-> (ImportSpec -> ImportSpec -> Bool) -> Eq ImportSpec
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 -> String
(Int -> ImportSpec -> ShowS)
-> (ImportSpec -> String)
-> ([ImportSpec] -> ShowS)
-> Show ImportSpec
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ImportSpec] -> ShowS
$cshowList :: [ImportSpec] -> ShowS
show :: ImportSpec -> String
$cshow :: ImportSpec -> String
showsPrec :: Int -> ImportSpec -> ShowS
$cshowsPrec :: Int -> ImportSpec -> ShowS
Show, (forall x. ImportSpec -> Rep ImportSpec x)
-> (forall x. Rep ImportSpec x -> ImportSpec) -> Generic ImportSpec
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 -> ()
(ImportSpec -> ()) -> NFData 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
(TySyn n -> TySyn n -> Bool)
-> (TySyn n -> TySyn n -> Bool) -> Eq (TySyn n)
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
[TySyn n] -> ShowS
TySyn n -> String
(Int -> TySyn n -> ShowS)
-> (TySyn n -> String) -> ([TySyn n] -> ShowS) -> Show (TySyn n)
forall n. Show n => Int -> TySyn n -> ShowS
forall n. Show n => [TySyn n] -> ShowS
forall n. Show n => TySyn n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TySyn n] -> ShowS
$cshowList :: forall n. Show n => [TySyn n] -> ShowS
show :: TySyn n -> String
$cshow :: forall n. Show n => TySyn n -> String
showsPrec :: Int -> TySyn n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> TySyn n -> ShowS
Show, (forall x. TySyn n -> Rep (TySyn n) x)
-> (forall x. Rep (TySyn n) x -> TySyn n) -> Generic (TySyn n)
forall x. Rep (TySyn n) x -> TySyn n
forall x. TySyn n -> Rep (TySyn n) x
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, TySyn n -> ()
(TySyn n -> ()) -> NFData (TySyn n)
forall n. NFData n => TySyn n -> ()
forall a. (a -> ()) -> NFData a
rnf :: TySyn n -> ()
$crnf :: forall n. NFData n => TySyn n -> ()
NFData, a -> TySyn b -> TySyn a
(a -> b) -> TySyn a -> TySyn b
(forall a b. (a -> b) -> TySyn a -> TySyn b)
-> (forall a b. a -> TySyn b -> TySyn a) -> Functor TySyn
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
<$ :: a -> TySyn b -> TySyn a
$c<$ :: forall a b. a -> TySyn b -> TySyn a
fmap :: (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
(PropSyn n -> PropSyn n -> Bool)
-> (PropSyn n -> PropSyn n -> Bool) -> Eq (PropSyn n)
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
[PropSyn n] -> ShowS
PropSyn n -> String
(Int -> PropSyn n -> ShowS)
-> (PropSyn n -> String)
-> ([PropSyn n] -> ShowS)
-> Show (PropSyn n)
forall n. Show n => Int -> PropSyn n -> ShowS
forall n. Show n => [PropSyn n] -> ShowS
forall n. Show n => PropSyn n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PropSyn n] -> ShowS
$cshowList :: forall n. Show n => [PropSyn n] -> ShowS
show :: PropSyn n -> String
$cshow :: forall n. Show n => PropSyn n -> String
showsPrec :: Int -> PropSyn n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> PropSyn n -> ShowS
Show, (forall x. PropSyn n -> Rep (PropSyn n) x)
-> (forall x. Rep (PropSyn n) x -> PropSyn n)
-> Generic (PropSyn n)
forall x. Rep (PropSyn n) x -> PropSyn n
forall x. PropSyn n -> Rep (PropSyn n) x
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, PropSyn n -> ()
(PropSyn n -> ()) -> NFData (PropSyn n)
forall n. NFData n => PropSyn n -> ()
forall a. (a -> ()) -> NFData a
rnf :: PropSyn n -> ()
$crnf :: forall n. NFData n => PropSyn n -> ()
NFData, a -> PropSyn b -> PropSyn a
(a -> b) -> PropSyn a -> PropSyn b
(forall a b. (a -> b) -> PropSyn a -> PropSyn b)
-> (forall a b. a -> PropSyn b -> PropSyn a) -> Functor PropSyn
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
<$ :: a -> PropSyn b -> PropSyn a
$c<$ :: forall a b. a -> PropSyn b -> PropSyn a
fmap :: (a -> b) -> PropSyn a -> PropSyn b
$cfmap :: forall a b. (a -> b) -> PropSyn a -> PropSyn b
Functor)

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

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

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

psFixity :: PropSyn name -> Maybe Fixity
psFixity :: 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
  { Bind name -> Located name
bName      :: Located name            -- ^ Defined thing
  , Bind name -> [Pattern name]
bParams    :: [Pattern name]          -- ^ Parameters
  , Bind name -> Located (BindDef name)
bDef       :: Located (BindDef name)  -- ^ Definition
  , Bind name -> Maybe (Schema name)
bSignature :: Maybe (Schema name)     -- ^ Optional type sig
  , Bind name -> Bool
bInfix     :: Bool                    -- ^ Infix operator?
  , Bind name -> Maybe Fixity
bFixity    :: Maybe Fixity            -- ^ Optional fixity info
  , Bind name -> [Pragma]
bPragmas   :: [Pragma]                -- ^ Optional pragmas
  , Bind name -> Bool
bMono      :: Bool                    -- ^ Is this a monomorphic binding
  , Bind name -> Maybe Text
bDoc       :: Maybe Text              -- ^ Optional doc string
  , Bind name -> ExportType
bExport    :: !ExportType
  } deriving (Bind name -> Bind name -> Bool
(Bind name -> Bind name -> Bool)
-> (Bind name -> Bind name -> Bool) -> Eq (Bind name)
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 x. Bind name -> Rep (Bind name) x)
-> (forall x. Rep (Bind name) x -> Bind name)
-> Generic (Bind name)
forall x. Rep (Bind name) x -> Bind name
forall x. Bind name -> Rep (Bind name) x
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, Bind name -> ()
(Bind name -> ()) -> NFData (Bind name)
forall name. NFData name => Bind name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Bind name -> ()
$crnf :: forall name. NFData name => Bind name -> ()
NFData, a -> Bind b -> Bind a
(a -> b) -> Bind a -> Bind b
(forall a b. (a -> b) -> Bind a -> Bind b)
-> (forall a b. a -> Bind b -> Bind a) -> Functor Bind
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
<$ :: a -> Bind b -> Bind a
$c<$ :: forall a b. a -> Bind b -> Bind a
fmap :: (a -> b) -> Bind a -> Bind b
$cfmap :: forall a b. (a -> b) -> Bind a -> Bind b
Functor, Int -> Bind name -> ShowS
[Bind name] -> ShowS
Bind name -> String
(Int -> Bind name -> ShowS)
-> (Bind name -> String)
-> ([Bind name] -> ShowS)
-> Show (Bind name)
forall name. Show name => Int -> Bind name -> ShowS
forall name. Show name => [Bind name] -> ShowS
forall name. Show name => Bind name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Bind name] -> ShowS
$cshowList :: forall name. Show name => [Bind name] -> ShowS
show :: Bind name -> String
$cshow :: forall name. Show name => Bind name -> String
showsPrec :: Int -> Bind name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Bind name -> ShowS
Show)

type LBindDef = Located (BindDef PName)

data BindDef name = DPrim
                  | DExpr (Expr name)
                    deriving (BindDef name -> BindDef name -> Bool
(BindDef name -> BindDef name -> Bool)
-> (BindDef name -> BindDef name -> Bool) -> Eq (BindDef name)
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
[BindDef name] -> ShowS
BindDef name -> String
(Int -> BindDef name -> ShowS)
-> (BindDef name -> String)
-> ([BindDef name] -> ShowS)
-> Show (BindDef name)
forall name. Show name => Int -> BindDef name -> ShowS
forall name. Show name => [BindDef name] -> ShowS
forall name. Show name => BindDef name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BindDef name] -> ShowS
$cshowList :: forall name. Show name => [BindDef name] -> ShowS
show :: BindDef name -> String
$cshow :: forall name. Show name => BindDef name -> String
showsPrec :: Int -> BindDef name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> BindDef name -> ShowS
Show, (forall x. BindDef name -> Rep (BindDef name) x)
-> (forall x. Rep (BindDef name) x -> BindDef name)
-> Generic (BindDef name)
forall x. Rep (BindDef name) x -> BindDef name
forall x. BindDef name -> Rep (BindDef name) x
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, BindDef name -> ()
(BindDef name -> ()) -> NFData (BindDef name)
forall name. NFData name => BindDef name -> ()
forall a. (a -> ()) -> NFData a
rnf :: BindDef name -> ()
$crnf :: forall name. NFData name => BindDef name -> ()
NFData, a -> BindDef b -> BindDef a
(a -> b) -> BindDef a -> BindDef b
(forall a b. (a -> b) -> BindDef a -> BindDef b)
-> (forall a b. a -> BindDef b -> BindDef a) -> Functor BindDef
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
<$ :: a -> BindDef b -> BindDef a
$c<$ :: forall a b. a -> BindDef b -> BindDef a
fmap :: (a -> b) -> BindDef a -> BindDef b
$cfmap :: forall a b. (a -> b) -> BindDef a -> BindDef b
Functor)

data Pragma   = PragmaNote String
              | PragmaProperty
                deriving (Pragma -> Pragma -> Bool
(Pragma -> Pragma -> Bool)
-> (Pragma -> Pragma -> Bool) -> Eq Pragma
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 -> String
(Int -> Pragma -> ShowS)
-> (Pragma -> String) -> ([Pragma] -> ShowS) -> Show Pragma
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pragma] -> ShowS
$cshowList :: [Pragma] -> ShowS
show :: Pragma -> String
$cshow :: Pragma -> String
showsPrec :: Int -> Pragma -> ShowS
$cshowsPrec :: Int -> Pragma -> ShowS
Show, (forall x. Pragma -> Rep Pragma x)
-> (forall x. Rep Pragma x -> Pragma) -> Generic Pragma
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 -> ()
(Pragma -> ()) -> NFData Pragma
forall a. (a -> ()) -> NFData a
rnf :: Pragma -> ()
$crnf :: Pragma -> ()
NFData)

data Newtype name = Newtype { Newtype name -> Located name
nName   :: Located name        -- ^ Type name
                            , Newtype name -> [TParam name]
nParams :: [TParam name]       -- ^ Type params
                            , Newtype name -> Rec (Type name)
nBody   :: Rec (Type name)     -- ^ Body
                            } deriving (Newtype name -> Newtype name -> Bool
(Newtype name -> Newtype name -> Bool)
-> (Newtype name -> Newtype name -> Bool) -> Eq (Newtype name)
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
[Newtype name] -> ShowS
Newtype name -> String
(Int -> Newtype name -> ShowS)
-> (Newtype name -> String)
-> ([Newtype name] -> ShowS)
-> Show (Newtype name)
forall name. Show name => Int -> Newtype name -> ShowS
forall name. Show name => [Newtype name] -> ShowS
forall name. Show name => Newtype name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Newtype name] -> ShowS
$cshowList :: forall name. Show name => [Newtype name] -> ShowS
show :: Newtype name -> String
$cshow :: forall name. Show name => Newtype name -> String
showsPrec :: Int -> Newtype name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Newtype name -> ShowS
Show, (forall x. Newtype name -> Rep (Newtype name) x)
-> (forall x. Rep (Newtype name) x -> Newtype name)
-> Generic (Newtype name)
forall x. Rep (Newtype name) x -> Newtype name
forall x. Newtype name -> Rep (Newtype name) x
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, Newtype name -> ()
(Newtype name -> ()) -> NFData (Newtype name)
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 { PrimType name -> Located name
primTName :: Located name
                              , PrimType name -> Located Kind
primTKind :: Located Kind
                              , PrimType name -> ([TParam name], [Prop name])
primTCts  :: ([TParam name], [Prop name])
                                -- ^ parameters are in the order used
                                -- by the type constructor.
                              , PrimType name -> Maybe Fixity
primTFixity :: Maybe Fixity
                              } deriving (Int -> PrimType name -> ShowS
[PrimType name] -> ShowS
PrimType name -> String
(Int -> PrimType name -> ShowS)
-> (PrimType name -> String)
-> ([PrimType name] -> ShowS)
-> Show (PrimType name)
forall name. Show name => Int -> PrimType name -> ShowS
forall name. Show name => [PrimType name] -> ShowS
forall name. Show name => PrimType name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PrimType name] -> ShowS
$cshowList :: forall name. Show name => [PrimType name] -> ShowS
show :: PrimType name -> String
$cshow :: forall name. Show name => PrimType name -> String
showsPrec :: Int -> PrimType name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> PrimType name -> ShowS
Show,(forall x. PrimType name -> Rep (PrimType name) x)
-> (forall x. Rep (PrimType name) x -> PrimType name)
-> Generic (PrimType name)
forall x. Rep (PrimType name) x -> PrimType name
forall x. PrimType name -> Rep (PrimType name) x
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,PrimType name -> ()
(PrimType name -> ()) -> NFData (PrimType name)
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
(ReplInput name -> ReplInput name -> Bool)
-> (ReplInput name -> ReplInput name -> Bool)
-> Eq (ReplInput name)
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
[ReplInput name] -> ShowS
ReplInput name -> String
(Int -> ReplInput name -> ShowS)
-> (ReplInput name -> String)
-> ([ReplInput name] -> ShowS)
-> Show (ReplInput name)
forall name. Show name => Int -> ReplInput name -> ShowS
forall name. Show name => [ReplInput name] -> ShowS
forall name. Show name => ReplInput name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ReplInput name] -> ShowS
$cshowList :: forall name. Show name => [ReplInput name] -> ShowS
show :: ReplInput name -> String
$cshow :: forall name. Show name => ReplInput name -> String
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
(ExportType -> ExportType -> Bool)
-> (ExportType -> ExportType -> Bool) -> Eq ExportType
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 -> String
(Int -> ExportType -> ShowS)
-> (ExportType -> String)
-> ([ExportType] -> ShowS)
-> Show ExportType
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExportType] -> ShowS
$cshowList :: [ExportType] -> ShowS
show :: ExportType -> String
$cshow :: ExportType -> String
showsPrec :: Int -> ExportType -> ShowS
$cshowsPrec :: Int -> ExportType -> ShowS
Show, Eq ExportType
Eq ExportType
-> (ExportType -> ExportType -> Ordering)
-> (ExportType -> ExportType -> Bool)
-> (ExportType -> ExportType -> Bool)
-> (ExportType -> ExportType -> Bool)
-> (ExportType -> ExportType -> Bool)
-> (ExportType -> ExportType -> ExportType)
-> (ExportType -> ExportType -> ExportType)
-> Ord 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
$cp1Ord :: Eq ExportType
Ord, (forall x. ExportType -> Rep ExportType x)
-> (forall x. Rep ExportType x -> ExportType) -> Generic ExportType
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 -> ()
(ExportType -> ()) -> NFData ExportType
forall a. (a -> ()) -> NFData a
rnf :: ExportType -> ()
$crnf :: ExportType -> ()
NFData)

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

data Expr n   = EVar n                          -- ^ @ x @
              | ELit Literal                    -- ^ @ 0x10 @
              | ENeg (Expr n)                   -- ^ @ -1 @
              | EComplement (Expr n)            -- ^ @ ~1 @
              | 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)
                deriving (Expr n -> Expr n -> Bool
(Expr n -> Expr n -> Bool)
-> (Expr n -> Expr n -> Bool) -> Eq (Expr n)
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
[Expr n] -> ShowS
Expr n -> String
(Int -> Expr n -> ShowS)
-> (Expr n -> String) -> ([Expr n] -> ShowS) -> Show (Expr n)
forall n. Show n => Int -> Expr n -> ShowS
forall n. Show n => [Expr n] -> ShowS
forall n. Show n => Expr n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Expr n] -> ShowS
$cshowList :: forall n. Show n => [Expr n] -> ShowS
show :: Expr n -> String
$cshow :: forall n. Show n => Expr n -> String
showsPrec :: Int -> Expr n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Expr n -> ShowS
Show, (forall x. Expr n -> Rep (Expr n) x)
-> (forall x. Rep (Expr n) x -> Expr n) -> Generic (Expr n)
forall x. Rep (Expr n) x -> Expr n
forall x. Expr n -> Rep (Expr n) x
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, Expr n -> ()
(Expr n -> ()) -> NFData (Expr n)
forall n. NFData n => Expr n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Expr n -> ()
$crnf :: forall n. NFData n => Expr n -> ()
NFData, a -> Expr b -> Expr a
(a -> b) -> Expr a -> Expr b
(forall a b. (a -> b) -> Expr a -> Expr b)
-> (forall a b. a -> Expr b -> Expr a) -> Functor Expr
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
<$ :: a -> Expr b -> Expr a
$c<$ :: forall a b. a -> Expr b -> Expr a
fmap :: (a -> b) -> Expr a -> Expr b
$cfmap :: forall a b. (a -> b) -> Expr a -> Expr b
Functor)

-- | Description of functions.  Only trivial information is provided here
--   by the parser.  The NoPat pass fills this in as required.
data FunDesc n =
  FunDesc
  { FunDesc n -> Maybe n
funDescrName      :: Maybe n   -- ^ Name of this function, if it has one
  , 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
(FunDesc n -> FunDesc n -> Bool)
-> (FunDesc n -> FunDesc n -> Bool) -> Eq (FunDesc n)
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
[FunDesc n] -> ShowS
FunDesc n -> String
(Int -> FunDesc n -> ShowS)
-> (FunDesc n -> String)
-> ([FunDesc n] -> ShowS)
-> Show (FunDesc n)
forall n. Show n => Int -> FunDesc n -> ShowS
forall n. Show n => [FunDesc n] -> ShowS
forall n. Show n => FunDesc n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [FunDesc n] -> ShowS
$cshowList :: forall n. Show n => [FunDesc n] -> ShowS
show :: FunDesc n -> String
$cshow :: forall n. Show n => FunDesc n -> String
showsPrec :: Int -> FunDesc n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> FunDesc n -> ShowS
Show, (forall x. FunDesc n -> Rep (FunDesc n) x)
-> (forall x. Rep (FunDesc n) x -> FunDesc n)
-> Generic (FunDesc n)
forall x. Rep (FunDesc n) x -> FunDesc n
forall x. FunDesc n -> Rep (FunDesc n) x
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, FunDesc n -> ()
(FunDesc n -> ()) -> NFData (FunDesc n)
forall n. NFData n => FunDesc n -> ()
forall a. (a -> ()) -> NFData a
rnf :: FunDesc n -> ()
$crnf :: forall n. NFData n => FunDesc n -> ()
NFData, a -> FunDesc b -> FunDesc a
(a -> b) -> FunDesc a -> FunDesc b
(forall a b. (a -> b) -> FunDesc a -> FunDesc b)
-> (forall a b. a -> FunDesc b -> FunDesc a) -> Functor FunDesc
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
<$ :: a -> FunDesc b -> FunDesc a
$c<$ :: forall a b. a -> FunDesc b -> FunDesc a
fmap :: (a -> b) -> FunDesc a -> FunDesc b
$cfmap :: forall a b. (a -> b) -> FunDesc a -> FunDesc b
Functor)

emptyFunDesc :: FunDesc n
emptyFunDesc :: FunDesc n
emptyFunDesc = Maybe n -> Int -> FunDesc n
forall n. Maybe n -> Int -> FunDesc n
FunDesc Maybe n
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
(UpdField n -> UpdField n -> Bool)
-> (UpdField n -> UpdField n -> Bool) -> Eq (UpdField n)
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
[UpdField n] -> ShowS
UpdField n -> String
(Int -> UpdField n -> ShowS)
-> (UpdField n -> String)
-> ([UpdField n] -> ShowS)
-> Show (UpdField n)
forall n. Show n => Int -> UpdField n -> ShowS
forall n. Show n => [UpdField n] -> ShowS
forall n. Show n => UpdField n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdField n] -> ShowS
$cshowList :: forall n. Show n => [UpdField n] -> ShowS
show :: UpdField n -> String
$cshow :: forall n. Show n => UpdField n -> String
showsPrec :: Int -> UpdField n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> UpdField n -> ShowS
Show, (forall x. UpdField n -> Rep (UpdField n) x)
-> (forall x. Rep (UpdField n) x -> UpdField n)
-> Generic (UpdField n)
forall x. Rep (UpdField n) x -> UpdField n
forall x. UpdField n -> Rep (UpdField n) x
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, UpdField n -> ()
(UpdField n -> ()) -> NFData (UpdField n)
forall n. NFData n => UpdField n -> ()
forall a. (a -> ()) -> NFData a
rnf :: UpdField n -> ()
$crnf :: forall n. NFData n => UpdField n -> ()
NFData, a -> UpdField b -> UpdField a
(a -> b) -> UpdField a -> UpdField b
(forall a b. (a -> b) -> UpdField a -> UpdField b)
-> (forall a b. a -> UpdField b -> UpdField a) -> Functor UpdField
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
<$ :: a -> UpdField b -> UpdField a
$c<$ :: forall a b. a -> UpdField b -> UpdField a
fmap :: (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
(UpdHow -> UpdHow -> Bool)
-> (UpdHow -> UpdHow -> Bool) -> Eq UpdHow
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 -> String
(Int -> UpdHow -> ShowS)
-> (UpdHow -> String) -> ([UpdHow] -> ShowS) -> Show UpdHow
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [UpdHow] -> ShowS
$cshowList :: [UpdHow] -> ShowS
show :: UpdHow -> String
$cshow :: UpdHow -> String
showsPrec :: Int -> UpdHow -> ShowS
$cshowsPrec :: Int -> UpdHow -> ShowS
Show, (forall x. UpdHow -> Rep UpdHow x)
-> (forall x. Rep UpdHow x -> UpdHow) -> Generic UpdHow
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 -> ()
(UpdHow -> ()) -> NFData 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
(TypeInst name -> TypeInst name -> Bool)
-> (TypeInst name -> TypeInst name -> Bool) -> Eq (TypeInst name)
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
[TypeInst name] -> ShowS
TypeInst name -> String
(Int -> TypeInst name -> ShowS)
-> (TypeInst name -> String)
-> ([TypeInst name] -> ShowS)
-> Show (TypeInst name)
forall name. Show name => Int -> TypeInst name -> ShowS
forall name. Show name => [TypeInst name] -> ShowS
forall name. Show name => TypeInst name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TypeInst name] -> ShowS
$cshowList :: forall name. Show name => [TypeInst name] -> ShowS
show :: TypeInst name -> String
$cshow :: forall name. Show name => TypeInst name -> String
showsPrec :: Int -> TypeInst name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> TypeInst name -> ShowS
Show, (forall x. TypeInst name -> Rep (TypeInst name) x)
-> (forall x. Rep (TypeInst name) x -> TypeInst name)
-> Generic (TypeInst name)
forall x. Rep (TypeInst name) x -> TypeInst name
forall x. TypeInst name -> Rep (TypeInst name) x
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, TypeInst name -> ()
(TypeInst name -> ()) -> NFData (TypeInst name)
forall name. NFData name => TypeInst name -> ()
forall a. (a -> ()) -> NFData a
rnf :: TypeInst name -> ()
$crnf :: forall name. NFData name => TypeInst name -> ()
NFData, a -> TypeInst b -> TypeInst a
(a -> b) -> TypeInst a -> TypeInst b
(forall a b. (a -> b) -> TypeInst a -> TypeInst b)
-> (forall a b. a -> TypeInst b -> TypeInst a) -> Functor TypeInst
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
<$ :: a -> TypeInst b -> TypeInst a
$c<$ :: forall a b. a -> TypeInst b -> TypeInst a
fmap :: (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
(Match name -> Match name -> Bool)
-> (Match name -> Match name -> Bool) -> Eq (Match name)
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
[Match name] -> ShowS
Match name -> String
(Int -> Match name -> ShowS)
-> (Match name -> String)
-> ([Match name] -> ShowS)
-> Show (Match name)
forall name. Show name => Int -> Match name -> ShowS
forall name. Show name => [Match name] -> ShowS
forall name. Show name => Match name -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Match name] -> ShowS
$cshowList :: forall name. Show name => [Match name] -> ShowS
show :: Match name -> String
$cshow :: forall name. Show name => Match name -> String
showsPrec :: Int -> Match name -> ShowS
$cshowsPrec :: forall name. Show name => Int -> Match name -> ShowS
Show, (forall x. Match name -> Rep (Match name) x)
-> (forall x. Rep (Match name) x -> Match name)
-> Generic (Match name)
forall x. Rep (Match name) x -> Match name
forall x. Match name -> Rep (Match name) x
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, Match name -> ()
(Match name -> ()) -> NFData (Match name)
forall name. NFData name => Match name -> ()
forall a. (a -> ()) -> NFData a
rnf :: Match name -> ()
$crnf :: forall name. NFData name => Match name -> ()
NFData, a -> Match b -> Match a
(a -> b) -> Match a -> Match b
(forall a b. (a -> b) -> Match a -> Match b)
-> (forall a b. a -> Match b -> Match a) -> Functor Match
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
<$ :: a -> Match b -> Match a
$c<$ :: forall a b. a -> Match b -> Match a
fmap :: (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
(Pattern n -> Pattern n -> Bool)
-> (Pattern n -> Pattern n -> Bool) -> Eq (Pattern n)
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
[Pattern n] -> ShowS
Pattern n -> String
(Int -> Pattern n -> ShowS)
-> (Pattern n -> String)
-> ([Pattern n] -> ShowS)
-> Show (Pattern n)
forall n. Show n => Int -> Pattern n -> ShowS
forall n. Show n => [Pattern n] -> ShowS
forall n. Show n => Pattern n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Pattern n] -> ShowS
$cshowList :: forall n. Show n => [Pattern n] -> ShowS
show :: Pattern n -> String
$cshow :: forall n. Show n => Pattern n -> String
showsPrec :: Int -> Pattern n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Pattern n -> ShowS
Show, (forall x. Pattern n -> Rep (Pattern n) x)
-> (forall x. Rep (Pattern n) x -> Pattern n)
-> Generic (Pattern n)
forall x. Rep (Pattern n) x -> Pattern n
forall x. Pattern n -> Rep (Pattern n) x
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, Pattern n -> ()
(Pattern n -> ()) -> NFData (Pattern n)
forall n. NFData n => Pattern n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Pattern n -> ()
$crnf :: forall n. NFData n => Pattern n -> ()
NFData, a -> Pattern b -> Pattern a
(a -> b) -> Pattern a -> Pattern b
(forall a b. (a -> b) -> Pattern a -> Pattern b)
-> (forall a b. a -> Pattern b -> Pattern a) -> Functor Pattern
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
<$ :: a -> Pattern b -> Pattern a
$c<$ :: forall a b. a -> Pattern b -> Pattern a
fmap :: (a -> b) -> Pattern a -> Pattern b
$cfmap :: forall a b. (a -> b) -> Pattern a -> Pattern b
Functor)

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

data TParam n = TParam { TParam n -> n
tpName  :: n
                       , TParam n -> Maybe Kind
tpKind  :: Maybe Kind
                       , TParam n -> Maybe Range
tpRange :: Maybe Range
                       }
  deriving (TParam n -> TParam n -> Bool
(TParam n -> TParam n -> Bool)
-> (TParam n -> TParam n -> Bool) -> Eq (TParam n)
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
[TParam n] -> ShowS
TParam n -> String
(Int -> TParam n -> ShowS)
-> (TParam n -> String) -> ([TParam n] -> ShowS) -> Show (TParam n)
forall n. Show n => Int -> TParam n -> ShowS
forall n. Show n => [TParam n] -> ShowS
forall n. Show n => TParam n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [TParam n] -> ShowS
$cshowList :: forall n. Show n => [TParam n] -> ShowS
show :: TParam n -> String
$cshow :: forall n. Show n => TParam n -> String
showsPrec :: Int -> TParam n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> TParam n -> ShowS
Show, (forall x. TParam n -> Rep (TParam n) x)
-> (forall x. Rep (TParam n) x -> TParam n) -> Generic (TParam n)
forall x. Rep (TParam n) x -> TParam n
forall x. TParam n -> Rep (TParam n) x
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, TParam n -> ()
(TParam n -> ()) -> NFData (TParam n)
forall n. NFData n => TParam n -> ()
forall a. (a -> ()) -> NFData a
rnf :: TParam n -> ()
$crnf :: forall n. NFData n => TParam n -> ()
NFData, a -> TParam b -> TParam a
(a -> b) -> TParam a -> TParam b
(forall a b. (a -> b) -> TParam a -> TParam b)
-> (forall a b. a -> TParam b -> TParam a) -> Functor TParam
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
<$ :: a -> TParam b -> TParam a
$c<$ :: forall a b. a -> TParam b -> TParam a
fmap :: (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)        -- ^ @ (ty) @
            | TInfix (Type n) (Located n) Fixity (Type n) -- ^ @ ty + ty @
              deriving (Type n -> Type n -> Bool
(Type n -> Type n -> Bool)
-> (Type n -> Type n -> Bool) -> Eq (Type n)
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
[Type n] -> ShowS
Type n -> String
(Int -> Type n -> ShowS)
-> (Type n -> String) -> ([Type n] -> ShowS) -> Show (Type n)
forall n. Show n => Int -> Type n -> ShowS
forall n. Show n => [Type n] -> ShowS
forall n. Show n => Type n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Type n] -> ShowS
$cshowList :: forall n. Show n => [Type n] -> ShowS
show :: Type n -> String
$cshow :: forall n. Show n => Type n -> String
showsPrec :: Int -> Type n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Type n -> ShowS
Show, (forall x. Type n -> Rep (Type n) x)
-> (forall x. Rep (Type n) x -> Type n) -> Generic (Type n)
forall x. Rep (Type n) x -> Type n
forall x. Type n -> Rep (Type n) x
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, Type n -> ()
(Type n -> ()) -> NFData (Type n)
forall n. NFData n => Type n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Type n -> ()
$crnf :: forall n. NFData n => Type n -> ()
NFData, a -> Type b -> Type a
(a -> b) -> Type a -> Type b
(forall a b. (a -> b) -> Type a -> Type b)
-> (forall a b. a -> Type b -> Type a) -> Functor Type
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
<$ :: a -> Type b -> Type a
$c<$ :: forall a b. a -> Type b -> Type a
fmap :: (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
(Prop n -> Prop n -> Bool)
-> (Prop n -> Prop n -> Bool) -> Eq (Prop n)
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
[Prop n] -> ShowS
Prop n -> String
(Int -> Prop n -> ShowS)
-> (Prop n -> String) -> ([Prop n] -> ShowS) -> Show (Prop n)
forall n. Show n => Int -> Prop n -> ShowS
forall n. Show n => [Prop n] -> ShowS
forall n. Show n => Prop n -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Prop n] -> ShowS
$cshowList :: forall n. Show n => [Prop n] -> ShowS
show :: Prop n -> String
$cshow :: forall n. Show n => Prop n -> String
showsPrec :: Int -> Prop n -> ShowS
$cshowsPrec :: forall n. Show n => Int -> Prop n -> ShowS
Show, (forall x. Prop n -> Rep (Prop n) x)
-> (forall x. Rep (Prop n) x -> Prop n) -> Generic (Prop n)
forall x. Rep (Prop n) x -> Prop n
forall x. Prop n -> Rep (Prop n) x
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, Prop n -> ()
(Prop n -> ()) -> NFData (Prop n)
forall n. NFData n => Prop n -> ()
forall a. (a -> ()) -> NFData a
rnf :: Prop n -> ()
$crnf :: forall n. NFData n => Prop n -> ()
NFData, a -> Prop b -> Prop a
(a -> b) -> Prop a -> Prop b
(forall a b. (a -> b) -> Prop a -> Prop b)
-> (forall a b. a -> Prop b -> Prop a) -> Functor Prop
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
<$ :: a -> Prop b -> Prop a
$c<$ :: forall a b. a -> Prop b -> Prop a
fmap :: (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 = Expr n -> Range -> Expr n
forall n. Expr n -> Range -> Expr n
ELocated Expr n
x Range
r

  dropLoc :: Expr n -> Expr n
dropLoc (ELocated Expr n
e Range
_) = Expr n -> Expr n
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) = Range -> Maybe Range
forall a. a -> Maybe a
Just Range
r
  getLoc Expr name
_              = Maybe Range
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 = name -> Maybe Kind -> Maybe Range -> TParam name
forall n. n -> Maybe Kind -> Maybe Range -> TParam n
TParam name
a Maybe Kind
b (Range -> Maybe Range
forall a. a -> Maybe a
Just Range
l)
  dropLoc :: TParam name -> TParam name
dropLoc (TParam name
a Maybe Kind
b Maybe Range
_)  = name -> Maybe Kind -> Maybe Range -> TParam name
forall n. n -> Maybe Kind -> Maybe Range -> TParam n
TParam name
a Maybe Kind
b Maybe Range
forall a. Maybe a
Nothing

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

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

  dropLoc :: Type name -> Type name
dropLoc (TLocated Type name
e Range
_) = Type name -> Type name
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 = Pattern name -> Range -> Pattern name
forall name. Pattern name -> Range -> Pattern name
PLocated

  dropLoc :: Pattern name -> Pattern name
dropLoc (PLocated Pattern name
e Range
_) = Pattern name -> Pattern name
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) = Range -> Maybe Range
forall a. a -> Maybe a
Just Range
r
  getLoc (PTyped Pattern name
r Type name
_)   = Pattern name -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc Pattern name
r
  getLoc (PVar Located name
x)       = Located name -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc Located name
x
  getLoc Pattern name
_              = Maybe Range
forall a. Maybe a
Nothing

instance HasLoc (Bind name) where
  getLoc :: Bind name -> Maybe Range
getLoc Bind name
b = (Located name, Located (BindDef name)) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Bind name -> Located name
forall name. Bind name -> Located name
bName Bind name
b, Bind name -> Located (BindDef name)
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)    = (Pattern name, Expr name) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Pattern name
p,Expr name
e)
  getLoc (MatchLet Bind name
b)   = Bind name -> Maybe Range
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 = (Located Ident, a) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Named a -> Located Ident
forall a. Named a -> Located Ident
name Named a
l, Named a -> a
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 = [TParam name]
-> [Prop name] -> Type name -> Maybe Range -> Schema name
forall n.
[TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
Forall [TParam name]
xs [Prop name]
ps Type name
t (Range -> Maybe Range
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
_)   = [TParam name]
-> [Prop name] -> Type name -> Maybe Range -> Schema name
forall n.
[TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
Forall [TParam name]
xs [Prop name]
ps Type name
t Maybe Range
forall a. Maybe a
Nothing

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

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

  dropLoc :: Decl name -> Decl name
dropLoc (DLocated Decl name
d Range
_) = Decl name -> Decl name
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 = a -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (a -> Maybe Range)
-> (TopLevel a -> a) -> TopLevel a -> Maybe Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TopLevel a -> a
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    -> TopLevel (Decl name) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (Decl name)
tld
      DPrimType TopLevel (PrimType name)
pt -> TopLevel (PrimType name) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (PrimType name)
pt
      TDNewtype TopLevel (Newtype name)
n -> TopLevel (Newtype name) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (Newtype name)
n
      Include Located String
lfp -> Located String -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc Located String
lfp
      DParameterType ParameterType name
d -> ParameterType name -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc ParameterType name
d
      DParameterFun ParameterFun name
d  -> ParameterFun name -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc ParameterFun name
d
      DParameterConstraint [Located (Prop name)]
d -> [Located (Prop name)] -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc [Located (Prop name)]
d
      DModule TopLevel (NestedModule name)
d -> TopLevel (NestedModule name) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc TopLevel (NestedModule name)
d
      DImport Located (ImportG (ImpName name))
d -> Located (ImportG (ImpName name)) -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc Located (ImportG (ImpName name))
d

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

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

instance HasLoc (ParameterFun name) where
  getLoc :: ParameterFun name -> Maybe Range
getLoc ParameterFun name
a = Located name -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (ParameterFun name -> Located name
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
    | [Range] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Range]
locs = Maybe Range
forall a. Maybe a
Nothing
    | Bool
otherwise = Range -> Maybe Range
forall a. a -> Maybe a
Just ([Range] -> Range
rCombs [Range]
locs)
    where
    locs :: [Range]
locs = [Maybe Range] -> [Range]
forall a. [Maybe a] -> [a]
catMaybes [ Located mname -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (ModuleG mname name -> Located mname
forall mname name. ModuleG mname name -> Located mname
mName ModuleG mname name
m)
                     , [Located Import] -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (ModuleG mname name -> [Located Import]
forall mname name. ModuleG mname name -> [Located Import]
mImports ModuleG mname name
m)
                     , [TopDecl name] -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (ModuleG mname name -> [TopDecl name]
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) = ModuleG name name -> Maybe Range
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
    | [Range] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Range]
locs = Maybe Range
forall a. Maybe a
Nothing
    | Bool
otherwise = Range -> Maybe Range
forall a. a -> Maybe a
Just ([Range] -> Range
rCombs [Range]
locs)
    where
    locs :: [Range]
locs = [Maybe Range] -> [Range]
forall a. [Maybe a] -> [a]
catMaybes ([ Located name -> Maybe Range
forall t. HasLoc t => t -> Maybe Range
getLoc (Newtype name -> Located name
forall name. Newtype name -> Located name
nName Newtype name
n)] [Maybe Range] -> [Maybe Range] -> [Maybe Range]
forall a. [a] -> [a] -> [a]
++ ((Ident, (Range, Type name)) -> Maybe Range)
-> [(Ident, (Range, Type name))] -> [Maybe Range]
forall a b. (a -> b) -> [a] -> [b]
map (Range -> Maybe Range
forall a. a -> Maybe a
Just (Range -> Maybe Range)
-> ((Ident, (Range, Type name)) -> Range)
-> (Ident, (Range, Type name))
-> Maybe Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Range, Type name) -> Range
forall a b. (a, b) -> a
fst ((Range, Type name) -> Range)
-> ((Ident, (Range, Type name)) -> (Range, Type name))
-> (Ident, (Range, Type name))
-> Range
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Ident, (Range, Type name)) -> (Range, Type name)
forall a b. (a, b) -> b
snd) (RecordMap Ident (Range, Type name) -> [(Ident, (Range, Type name))]
forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields (Newtype name -> RecordMap Ident (Range, Type name)
forall name. Newtype name -> Rec (Type name)
nBody Newtype name
n)))


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





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


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

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

ppNamed' :: PP a => String -> (Ident, (Range, a)) -> Doc
ppNamed' :: String -> (Ident, (Range, a)) -> Doc
ppNamed' String
s (Ident
i,(Range
_,a
v)) = Ident -> Doc
forall a. PP a => a -> Doc
pp Ident
i Doc -> Doc -> Doc
<+> String -> Doc
text String
s Doc -> Doc -> Doc
<+> a -> 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
_ = Int -> ModuleG mname name -> Doc
forall name mname.
(Show name, PPName mname, PPName name) =>
Int -> ModuleG mname name -> Doc
ppModule Int
0

ppModule :: (Show name, PPName mname, PPName name) =>
  Int -> ModuleG mname name -> Doc
ppModule :: Int -> ModuleG mname name -> Doc
ppModule Int
n ModuleG mname name
m =
  String -> Doc
text String
"module" Doc -> Doc -> Doc
<+> Located mname -> Doc
forall a. PP a => Located a -> Doc
ppL (ModuleG mname name -> Located mname
forall mname name. ModuleG mname name -> Located mname
mName ModuleG mname name
m) Doc -> Doc -> Doc
<+> String -> Doc
text String
"where" Doc -> Doc -> Doc
$$ Int -> Doc -> Doc
nest Int
n Doc
body
  where
  body :: Doc
body = [Doc] -> Doc
vcat ((Located Import -> Doc) -> [Located Import] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Located Import -> Doc
forall a. PP a => Located a -> Doc
ppL (ModuleG mname name -> [Located Import]
forall mname name. ModuleG mname name -> [Located Import]
mImports ModuleG mname name
m))
      Doc -> Doc -> Doc
$$ [Doc] -> Doc
vcat ((TopDecl name -> Doc) -> [TopDecl name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TopDecl name -> Doc
forall a. PP a => a -> Doc
pp (ModuleG mname name -> [TopDecl name]
forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m))



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


instance (Show name, PPName name) => PP (Program name) where
  ppPrec :: Int -> Program name -> Doc
ppPrec Int
_ (Program [TopDecl name]
ds) = [Doc] -> Doc
vcat ((TopDecl name -> Doc) -> [TopDecl name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TopDecl name -> Doc
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   -> TopLevel (Decl name) -> Doc
forall a. PP a => a -> Doc
pp TopLevel (Decl name)
d
      DPrimType TopLevel (PrimType name)
p -> TopLevel (PrimType name) -> Doc
forall a. PP a => a -> Doc
pp TopLevel (PrimType name)
p
      TDNewtype TopLevel (Newtype name)
n -> TopLevel (Newtype name) -> Doc
forall a. PP a => a -> Doc
pp TopLevel (Newtype name)
n
      Include Located String
l   -> String -> Doc
text String
"include" Doc -> Doc -> Doc
<+> String -> Doc
text (ShowS
forall a. Show a => a -> String
show (Located String -> String
forall a. Located a -> a
thing Located String
l))
      DParameterFun ParameterFun name
d -> ParameterFun name -> Doc
forall a. PP a => a -> Doc
pp ParameterFun name
d
      DParameterType ParameterType name
d -> ParameterType name -> Doc
forall a. PP a => a -> Doc
pp ParameterType name
d
      DParameterConstraint [Located (Prop name)]
d ->
        Doc
"parameter" Doc -> Doc -> Doc
<+> Doc
"type" Doc -> Doc -> Doc
<+> Doc
"constraint" Doc -> Doc -> Doc
<+> Doc
prop
        where prop :: Doc
prop = case (Located (Prop name) -> Doc) -> [Located (Prop name)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Prop name -> Doc
forall a. PP a => a -> Doc
pp (Prop name -> Doc)
-> (Located (Prop name) -> Prop name) -> Located (Prop name) -> Doc
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Located (Prop name) -> Prop name
forall a. Located a -> a
thing) [Located (Prop name)]
d of
                       [Doc
x] -> Doc
x
                       []  -> Doc
"()"
                       [Doc]
xs  -> Int -> Doc -> Doc
nest Int
1 (Doc -> Doc
parens ([Doc] -> Doc
commaSepFill [Doc]
xs))
      DModule TopLevel (NestedModule name)
d -> TopLevel (NestedModule name) -> Doc
forall a. PP a => a -> Doc
pp TopLevel (NestedModule name)
d
      DImport Located (ImportG (ImpName name))
i -> ImportG (ImpName name) -> Doc
forall a. PP a => a -> Doc
pp (Located (ImportG (ImpName name)) -> ImportG (ImpName name)
forall a. Located a -> a
thing Located (ImportG (ImpName name))
i)

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
<+> Located name -> Doc
forall a. PP a => a -> Doc
pp (PrimType name -> Located name
forall name. PrimType name -> Located name
primTName PrimType name
pt) Doc -> Doc -> Doc
<+> Doc
":" Doc -> Doc -> Doc
<+> Located Kind -> Doc
forall a. PP a => a -> Doc
pp (PrimType name -> Located Kind
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 = String -> Doc
text String
"parameter" Doc -> Doc -> Doc
<+> String -> Doc
text String
"type" Doc -> Doc -> Doc
<+>
               Located name -> Doc
forall a. PPName a => a -> Doc
ppPrefixName (ParameterType name -> Located name
forall name. ParameterType name -> Located name
ptName ParameterType name
a) Doc -> Doc -> Doc
<+> String -> Doc
text String
":" Doc -> Doc -> Doc
<+> Kind -> Doc
forall a. PP a => a -> Doc
pp (ParameterType name -> Kind
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 = String -> Doc
text String
"parameter" Doc -> Doc -> Doc
<+> Located name -> Doc
forall a. PPName a => a -> Doc
ppPrefixName (ParameterFun name -> Located name
forall name. ParameterFun name -> Located name
pfName ParameterFun name
a) Doc -> Doc -> Doc
<+> String -> Doc
text String
":"
                  Doc -> Doc -> Doc
<+> Schema name -> Doc
forall a. PP a => a -> Doc
pp (ParameterFun name -> Schema name
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 ((Located name -> Doc) -> [Located name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Located name -> Doc
forall a. PP a => Located a -> Doc
ppL [Located name]
xs) Doc -> Doc -> Doc
<+> String -> Doc
text String
":" Doc -> Doc -> Doc
<+> Schema name -> Doc
forall a. PP a => a -> Doc
pp Schema name
s
      DPatBind Pattern name
p Expr name
e    -> Pattern name -> Doc
forall a. PP a => a -> Doc
pp Pattern name
p Doc -> Doc -> Doc
<+> String -> Doc
text String
"=" Doc -> Doc -> Doc
<+> Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e
      DBind Bind name
b         -> Int -> Bind name -> Doc
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" Doc -> [Doc] -> [Doc]
forall a. a -> [a] -> [a]
: (Bind name -> Doc) -> [Bind name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Bind name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
n) [Bind name]
bs))
      DFixity Fixity
f [Located name]
ns    -> Fixity -> [Located name] -> Doc
forall name. PPName name => Fixity -> [Located name] -> Doc
ppFixity Fixity
f [Located name]
ns
      DPragma [Located name]
xs Pragma
p    -> [Located name] -> Pragma -> Doc
forall name. PPName name => [Located name] -> Pragma -> Doc
ppPragma [Located name]
xs Pragma
p
      DType TySyn name
ts        -> Int -> TySyn name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
n TySyn name
ts
      DProp PropSyn name
ps        -> Int -> PropSyn name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
n PropSyn name
ps
      DLocated Decl name
d Range
_    -> Int -> Decl name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
n Decl name
d

ppFixity :: PPName name => Fixity -> [Located name] -> Doc
ppFixity :: Fixity -> [Located name] -> Doc
ppFixity (Fixity Assoc
LeftAssoc  Int
i) [Located name]
ns = String -> Doc
text String
"infixl" Doc -> Doc -> Doc
<+> Int -> Doc
int Int
i Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep ((Located name -> Doc) -> [Located name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Located name -> Doc
forall a. PP a => a -> Doc
pp [Located name]
ns)
ppFixity (Fixity Assoc
RightAssoc Int
i) [Located name]
ns = String -> Doc
text String
"infixr" Doc -> Doc -> Doc
<+> Int -> Doc
int Int
i Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep ((Located name -> Doc) -> [Located name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Located name -> Doc
forall a. PP a => a -> Doc
pp [Located name]
ns)
ppFixity (Fixity Assoc
NonAssoc   Int
i) [Located name]
ns = String -> Doc
text String
"infix"  Doc -> Doc -> Doc
<+> Int -> Doc
int Int
i Doc -> Doc -> Doc
<+> [Doc] -> Doc
commaSep ((Located name -> Doc) -> [Located name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Located name -> Doc
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 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep
    [ [Doc] -> Doc
fsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ [String -> Doc
text String
"newtype", Located name -> Doc
forall a. PP a => Located a -> Doc
ppL (Newtype name -> Located name
forall name. Newtype name -> Located name
nName Newtype name
nt)] [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ (TParam name -> Doc) -> [TParam name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TParam name -> Doc
forall a. PP a => a -> Doc
pp (Newtype name -> [TParam name]
forall name. Newtype name -> [TParam name]
nParams Newtype name
nt) [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Char -> Doc
char Char
'=']
    , [Doc] -> Doc
ppRecord (((Ident, (Range, Type name)) -> Doc)
-> [(Ident, (Range, Type name))] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> (Ident, (Range, Type name)) -> Doc
forall a. PP a => String -> (Ident, (Range, a)) -> Doc
ppNamed' String
":") (RecordMap Ident (Range, Type name) -> [(Ident, (Range, Type name))]
forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields (Newtype name -> RecordMap Ident (Range, Type name)
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 = String -> Doc
text String
"import" Doc -> Doc -> Doc
<+> [Doc] -> Doc
sep ([mname -> Doc
forall a. PP a => a -> Doc
pp (ImportG mname -> mname
forall mname. ImportG mname -> mname
iModule ImportG mname
d)] [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Doc]
mbAs [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Doc]
mbSpec)
    where
    mbAs :: [Doc]
mbAs   = [Doc] -> (ModName -> [Doc]) -> Maybe ModName -> [Doc]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ ModName
name -> [String -> Doc
text String
"as" Doc -> Doc -> Doc
<+> ModName -> Doc
forall a. PP a => a -> Doc
pp ModName
name]) (ImportG mname -> Maybe ModName
forall mname. ImportG mname -> Maybe ModName
iAs ImportG mname
d)
    mbSpec :: [Doc]
mbSpec = [Doc] -> (ImportSpec -> [Doc]) -> Maybe ImportSpec -> [Doc]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\ImportSpec
x -> [ImportSpec -> Doc
forall a. PP a => a -> Doc
pp ImportSpec
x]) (ImportG mname -> Maybe ImportSpec
forall mname. ImportG mname -> Maybe ImportSpec
iSpec ImportG mname
d)

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    -> ModName -> Doc
forall a. PP a => a -> Doc
pp ModName
x
      ImpNested name
x -> Doc
"submodule" Doc -> Doc -> Doc
<+> name -> 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 -> String -> Doc
text String
"hiding" Doc -> Doc -> Doc
<+> Doc -> Doc
parens ([Doc] -> Doc
commaSep ((Ident -> Doc) -> [Ident] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> Doc
forall a. PP a => a -> Doc
pp [Ident]
names))
    Only [Ident]
names   ->                   Doc -> Doc
parens ([Doc] -> Doc
commaSep ((Ident -> Doc) -> [Ident] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Ident -> Doc
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 = a -> Doc
forall a. PP a => a -> Doc
pp (TopLevel a -> a
forall a. TopLevel a -> a
tlValue TopLevel a
tl)


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

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

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

          lhsOp :: Doc
lhsOp = case Bind name -> [Pattern name]
forall name. Bind name -> [Pattern name]
bParams Bind name
b of
                    [Pattern name
x,Pattern name
y] -> Pattern name -> Doc
forall a. PP a => a -> Doc
pp Pattern name
x Doc -> Doc -> Doc
<+> Located name -> Doc
forall a. PP a => Located a -> Doc
ppL Located name
f Doc -> Doc -> Doc
<+> Pattern name -> Doc
forall a. PP a => a -> Doc
pp Pattern name
y
                    [Pattern name]
xs -> Doc -> Doc
parens (Doc -> Doc
parens (Located name -> Doc
forall a. PP a => Located a -> Doc
ppL Located name
f) Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep ((Pattern name -> Doc) -> [Pattern name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Pattern name -> Doc
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     = String -> Doc
text String
"<primitive>"
  ppPrec Int
p (DExpr Expr name
e) = Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
p Expr name
e


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 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$
      [ [Doc] -> Doc
fsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ [String -> Doc
text String
"type", Located name -> Doc
forall a. PP a => Located a -> Doc
ppL Located name
x] [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ (TParam name -> Doc) -> [TParam name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> TParam name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1) [TParam name]
xs [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [String -> Doc
text String
"="]
      , Type name -> Doc
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 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$
      [ [Doc] -> Doc
fsep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ [String -> Doc
text String
"constraint", Located name -> Doc
forall a. PP a => Located a -> Doc
ppL Located name
x] [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ (TParam name -> Doc) -> [TParam name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> TParam name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1) [TParam name]
xs [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [String -> Doc
text String
"="]
      , Doc -> Doc
parens ([Doc] -> Doc
commaSep ((Prop name -> Doc) -> [Prop name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Prop name -> Doc
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      -> String -> Doc
text (Char -> String
forall a. Show a => a -> String
show Char
c)
      ECFrac Rational
n FracInfo
i    -> Rational -> FracInfo -> Doc
ppFracLit Rational
n FracInfo
i
      ECString String
s    -> String -> Doc
text (ShowS
forall a. Show a => a -> String
show String
s)

ppFracLit :: Rational -> FracInfo -> Doc
ppFracLit :: Rational -> FracInfo -> Doc
ppFracLit Rational
x FracInfo
i
  | Double -> Rational
forall a. Real a => a -> Rational
toRational Double
dbl Rational -> Rational -> Bool
forall a. Eq a => a -> a -> Bool
== Rational
x =
    case FracInfo
i of
      BinFrac Text
_ -> Doc
frac
      OctFrac Text
_ -> Doc
frac
      DecFrac Text
_ -> String -> Doc
text (Double -> ShowS
forall a. RealFloat a => a -> ShowS
showFloat Double
dbl String
"")
      HexFrac Text
_ -> String -> Doc
text (Double -> ShowS
forall a. RealFloat a => a -> ShowS
showHFloat Double
dbl String
"")
  | Bool
otherwise = Doc
frac
  where
  dbl :: Double
dbl = Rational -> Double
forall a. Fractional a => Rational -> a
fromRational Rational
x :: Double
  frac :: Doc
frac = Doc
"fraction`" Doc -> Doc -> Doc
<.> Doc -> Doc
braces
                      ([Doc] -> Doc
commaSep ((Integer -> Doc) -> [Integer] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Integer -> Doc
integer [ Rational -> Integer
forall a. Ratio a -> a
numerator Rational
x, Rational -> Integer
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 -> String -> Int -> Doc
pad Integer
2  String
"0b" Int
w
    OctLit Text
_ Int
w -> Integer -> String -> Int -> Doc
pad Integer
8  String
"0o" Int
w
    HexLit Text
_ Int
w -> Integer -> String -> Int -> Doc
pad Integer
16 String
"0x" Int
w
    PolyLit Int
w  -> String -> Doc
text String
"<|" Doc -> Doc -> Doc
<+> Int -> Doc
poly Int
w Doc -> Doc -> Doc
<+> String -> Doc
text String
"|>"
  where
  pad :: Integer -> String -> Int -> Doc
pad Integer
base String
pref Int
w =
    let txt :: String
txt = Integer -> (Int -> Char) -> Integer -> ShowS
forall a. (Integral a, Show a) => a -> (Int -> Char) -> a -> ShowS
showIntAtBase Integer
base (String
"0123456789abcdef" String -> Int -> Char
forall a. [a] -> Int -> a
!!) Integer
n String
""
    in String -> Doc
text String
pref Doc -> Doc -> Doc
<.> String -> Doc
text (Int -> Char -> String
forall a. Int -> a -> [a]
replicate (Int
w Int -> Int -> Int
forall a. Num a => a -> a -> a
- String -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length String
txt) Char
'0') Doc -> Doc -> Doc
<.> String -> Doc
text String
txt

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

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

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

  bits :: Maybe a -> [a] -> a -> a -> ([a], Maybe a)
bits Maybe a
d [a]
res a
p a
num
    | a
num a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
0  = ([a]
res,Maybe a
d)
    | a -> Bool
forall a. Integral a => a -> Bool
even a
num  = Maybe a -> [a] -> a -> a -> ([a], Maybe a)
bits Maybe a
d             [a]
res  (a
p a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) (a
num a -> Int -> a
forall a. Bits a => a -> Int -> a
`shiftR` Int
1)
    | Bool
otherwise = Maybe a -> [a] -> a -> a -> ([a], Maybe a)
bits (a -> Maybe a
forall a. a -> Maybe a
Just a
p) (a
p a -> [a] -> [a]
forall a. a -> [a] -> [a]
: [a]
res) (a
p a -> a -> a
forall a. Num a => a -> a -> a
+ a
1) (a
num a -> Int -> a
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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
< Int
contextPrec) Doc
doc

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

asEApps :: Expr n -> (Expr n, [Expr n])
asEApps :: Expr n -> (Expr n, [Expr n])
asEApps Expr n
expr = Expr n -> [Expr n] -> (Expr n, [Expr n])
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 Expr n -> Maybe (Expr n, Expr n)
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 Expr n -> [Expr n] -> [Expr n]
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)   = Type name -> Doc
forall a. PP a => a -> Doc
pp Type name
t
  ppPrec Int
_ (NamedInst Named (Type name)
x) = String -> Named (Type name) -> Doc
forall a. PP a => String -> Named a -> Doc
ppNamed String
"=" 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        -> name -> Doc
forall a. PPName a => a -> Doc
ppPrefixName name
x
      ELit Literal
x        -> Literal -> Doc
forall a. PP a => a -> Doc
pp Literal
x

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

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

      ETypeVal Type name
t    -> String -> Doc
text String
"`" Doc -> Doc -> Doc
<.> Int -> Type name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
5 Type name
t     -- XXX
      EAppT Expr name
e [TypeInst name]
ts    -> Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e Doc -> Doc -> Doc
<.> String -> Doc
text String
"`" Doc -> Doc -> Doc
<.> Doc -> Doc
braces ([Doc] -> Doc
commaSep ((TypeInst name -> Doc) -> [TypeInst name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TypeInst name -> Doc
forall a. PP a => a -> Doc
pp [TypeInst name]
ts))
      ESel    Expr name
e Selector
l   -> Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e Doc -> Doc -> Doc
<.> String -> Doc
text String
"." Doc -> Doc -> Doc
<.> Selector -> 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 ((String -> Doc
text String
"\\" Doc -> Doc -> Doc
<.> [Doc] -> Doc
hsep ((Pattern name -> Doc) -> [Pattern name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Pattern name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
3) [Pattern name]
xs)) Doc -> Doc -> Doc
<+>
                                 String -> Doc
text String
"->" Doc -> Doc -> Doc
<+> Expr name -> 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 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep [ String -> Doc
text String
"if"   Doc -> Doc -> Doc
<+> Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e1
                                      , String -> Doc
text String
"then" Doc -> Doc -> Doc
<+> Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e2
                                      , String -> Doc
text String
"else" Doc -> Doc -> Doc
<+> Expr name -> 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 (Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
2 Expr name
e Doc -> Doc -> Doc
<+> String -> Doc
text String
":" Doc -> Doc -> Doc
<+> Type name -> 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 (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
align (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
vsep
                         [ Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e
                         , Doc -> Int -> Doc -> Doc
hang Doc
"where" Int
2 ([Doc] -> Doc
vcat ((Decl name -> Doc) -> [Decl name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Decl name -> Doc
forall a. PP a => a -> Doc
pp [Decl name]
ds))
                         ]

      -- infix applications
      Expr name
_ | Just Infix name (Expr name)
ifix <- Expr name -> Maybe (Infix name (Expr name))
forall op. PPName op => Expr op -> Maybe (Infix op (Expr op))
isInfix Expr name
expr ->
              Bool -> Doc -> Doc
optParens (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
2)
              (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Int
-> (Expr name -> Maybe (Infix name (Expr name)))
-> Infix name (Expr name)
-> Doc
forall thing op.
(PP thing, PP op) =>
Int -> (thing -> Maybe (Infix op thing)) -> Infix op thing -> Doc
ppInfix Int
2 Expr name -> Maybe (Infix name (Expr name))
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) = Expr name -> (Expr name, [Expr name])
forall n. Expr n -> (Expr n, [Expr n])
asEApps Expr name
expr in
                       Int -> Int -> Doc -> Doc
wrap Int
n Int
3 (Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
3 Expr name
e Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep ((Expr name -> Doc) -> [Expr name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
4) [Expr name]
es))

      ELocated Expr name
e Range
_  -> Int -> Expr name -> Doc
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 (String -> Doc
text String
"splitAt" Doc -> Doc -> Doc
<+> Int -> Expr name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
4 Expr name
e)

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

      EInfix Expr name
e1 Located name
op Fixity
_ Expr name
e2 -> Int -> Int -> Doc -> Doc
wrap Int
n Int
0 (Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e1 Doc -> Doc -> Doc
<+> name -> Doc
forall a. PPName a => a -> Doc
ppInfixName (Located name -> name
forall a. Located a -> a
thing Located name
op) Doc -> Doc -> Doc
<+> Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e2)
   where
   isInfix :: Expr op -> Maybe (Infix op (Expr op))
isInfix (EApp (EApp (EVar op
ieOp) Expr op
ieLeft) Expr op
ieRight) = do
     Fixity
ieFixity <- op -> Maybe Fixity
forall a. PPName a => a -> Maybe Fixity
ppNameFixity op
ieOp
     Infix op (Expr op) -> Maybe (Infix op (Expr op))
forall (m :: * -> *) a. Monad m => a -> m a
return Infix :: forall op thing. op -> thing -> thing -> Fixity -> Infix op thing
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
_ = Maybe (Infix op (Expr op))
forall a. Maybe a
Nothing

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 ((Located Selector -> Selector) -> [Located Selector] -> [Selector]
forall a b. (a -> b) -> [a] -> [b]
map Located Selector -> Selector
forall a. Located a -> a
thing [Located Selector]
xs) Doc -> Doc -> Doc
<+> UpdHow -> Doc
forall a. PP a => a -> Doc
pp UpdHow
h Doc -> Doc -> Doc
<+> Expr name -> 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        -> name -> Doc
forall a. PP a => a -> Doc
pp (Located name -> name
forall a. Located a -> a
thing Located name
x)
      Pattern name
PWild         -> Char -> Doc
char Char
'_'
      PTuple [Pattern name]
ps     -> [Doc] -> Doc
ppTuple ((Pattern name -> Doc) -> [Pattern name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Pattern name -> Doc
forall a. PP a => a -> Doc
pp [Pattern name]
ps)
      PRecord Rec (Pattern name)
fs    -> [Doc] -> Doc
ppRecord (((Ident, (Range, Pattern name)) -> Doc)
-> [(Ident, (Range, Pattern name))] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> (Ident, (Range, Pattern name)) -> Doc
forall a. PP a => String -> (Ident, (Range, a)) -> Doc
ppNamed' String
"=") (Rec (Pattern name) -> [(Ident, (Range, Pattern name))]
forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields Rec (Pattern name)
fs))
      PList [Pattern name]
ps      -> [Doc] -> Doc
ppList ((Pattern name -> Doc) -> [Pattern name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Pattern name -> Doc
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 (Int -> Pattern name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Pattern name
p  Doc -> Doc -> Doc
<+> String -> Doc
text String
":" Doc -> Doc -> Doc
<+> Type name -> 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 (Int -> Pattern name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Pattern name
p1 Doc -> Doc -> Doc
<+> String -> Doc
text String
"#" Doc -> Doc -> Doc
<+> Int -> Pattern name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Pattern name
p2)
      PLocated Pattern name
p Range
_  -> Int -> Pattern name -> Doc
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)  = Pattern name -> Doc
forall a. PP a => a -> Doc
pp Pattern name
p Doc -> Doc -> Doc
<+> String -> Doc
text String
"<-" Doc -> Doc -> Doc
<+> Expr name -> Doc
forall a. PP a => a -> Doc
pp Expr name
e
  ppPrec Int
_ (MatchLet Bind name
b) = Bind name -> Doc
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 [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Doc]
preds [Doc] -> [Doc] -> [Doc]
forall a. [a] -> [a] -> [a]
++ [Type name -> Doc
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 ((TParam name -> Doc) -> [TParam name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map TParam name -> Doc
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 ((Prop name -> Doc) -> [Prop name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Prop name -> Doc
forall a. PP a => a -> Doc
pp [Prop name]
ps))) Doc -> Doc -> Doc
<+> String -> Doc
text String
"=>"]

instance PP Kind where
  ppPrec :: Int -> Kind -> Doc
ppPrec Int
_ Kind
KType  = String -> Doc
text String
"*"
  ppPrec Int
_ Kind
KNum   = String -> Doc
text String
"#"
  ppPrec Int
_ Kind
KProp  = String -> Doc
text String
"@"
  ppPrec Int
n (KFun Kind
k1 Kind
k2) = Int -> Int -> Doc -> Doc
wrap Int
n Int
1 (Int -> Kind -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Kind
k1 Doc -> Doc -> Doc
<+> Doc
"->" Doc -> Doc -> Doc
<+> Int -> Kind -> 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     = String -> Doc
text String
"a value type"
cppKind Kind
KNum      = String -> Doc
text String
"a numeric type"
cppKind Kind
KProp     = String -> Doc
text String
"a constraint type"
cppKind (KFun {}) = String -> Doc
text String
"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
_)   = Int -> name -> Doc
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 (name -> Doc
forall a. PP a => a -> Doc
pp name
p Doc -> Doc -> Doc
<+> String -> Doc
text String
":" Doc -> Doc -> Doc
<+> Kind -> 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          -> String -> Doc
text String
"_"
      TTuple [Type name]
ts      -> Doc -> Doc
parens (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
commaSep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Type name -> Doc) -> [Type name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map Type name -> Doc
forall a. PP a => a -> Doc
pp [Type name]
ts
      TTyApp [Named (Type name)]
fs      -> Doc -> Doc
braces (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
commaSep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ (Named (Type name) -> Doc) -> [Named (Type name)] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> Named (Type name) -> Doc
forall a. PP a => String -> Named a -> Doc
ppNamed String
" = ") [Named (Type name)]
fs
      TRecord Rec (Type name)
fs     -> Doc -> Doc
braces (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
commaSep ([Doc] -> Doc) -> [Doc] -> Doc
forall a b. (a -> b) -> a -> b
$ ((Ident, (Range, Type name)) -> Doc)
-> [(Ident, (Range, Type name))] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (String -> (Ident, (Range, Type name)) -> Doc
forall a. PP a => String -> (Ident, (Range, a)) -> Doc
ppNamed' String
":") (Rec (Type name) -> [(Ident, (Range, Type name))]
forall a b. (Show a, Ord a) => RecordMap a b -> [(a, b)]
displayFields Rec (Type name)
fs)
      Type name
TBit           -> String -> Doc
text String
"Bit"
      TNum Integer
x         -> Integer -> Doc
integer Integer
x
      TChar Char
x        -> String -> Doc
text (Char -> String
forall a. Show a => a -> String
show Char
x)
      TSeq Type name
t1 Type name
TBit   -> Doc -> Doc
brackets (Type name -> Doc
forall a. PP a => a -> Doc
pp Type name
t1)
      TSeq Type name
t1 Type name
t2     -> Bool -> Doc -> Doc
optParens (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
3)
                      (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ Doc -> Doc
brackets (Type name -> Doc
forall a. PP a => a -> Doc
pp Type name
t1) Doc -> Doc -> Doc
<.> Int -> Type name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
3 Type name
t2

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

      TUser name
f [Type name]
ts     -> Bool -> Doc -> Doc
optParens (Int
n Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
3)
                      (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ name -> Doc
forall a. PPName a => a -> Doc
ppPrefixName name
f Doc -> Doc -> Doc
<+> [Doc] -> Doc
fsep ((Type name -> Doc) -> [Type name] -> [Doc]
forall a b. (a -> b) -> [a] -> [b]
map (Int -> Type name -> Doc
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 Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
> Int
1)
                      (Doc -> Doc) -> Doc -> Doc
forall a b. (a -> b) -> a -> b
$ [Doc] -> Doc
sep [Int -> Type name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
2 Type name
t1 Doc -> Doc -> Doc
<+> String -> Doc
text String
"->", Int -> Type name -> Doc
forall a. PP a => Int -> a -> Doc
ppPrec Int
1 Type name
t2]

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

      TParens Type name
t      -> Doc -> Doc
parens (Type name -> Doc
forall a. PP a => a -> Doc
pp Type name
t)

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


--------------------------------------------------------------------------------
-- 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 :: Position -> Position -> String -> 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 :: String
source = String
"" }

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

instance NoPos Range where
  noPos :: Range -> Range
noPos Range
_ = Range :: Position -> Position -> String -> 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 :: String
source = String
"" }

instance NoPos t => NoPos [t]       where noPos :: [t] -> [t]
noPos = (t -> t) -> [t] -> [t]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap t -> t
forall t. NoPos t => t -> t
noPos
instance NoPos t => NoPos (Maybe t) where noPos :: Maybe t -> Maybe t
noPos = (t -> t) -> Maybe t -> Maybe t
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap t -> t
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) = (a -> a
forall t. NoPos t => t -> t
noPos a
a, b -> b
forall t. NoPos t => t -> t
noPos b
b)

instance NoPos (Program name) where
  noPos :: Program name -> Program name
noPos (Program [TopDecl name]
x) = [TopDecl name] -> Program name
forall name. [TopDecl name] -> Program name
Program ([TopDecl name] -> [TopDecl name]
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 :: forall mname name.
Located mname
-> Maybe (Located ModName) -> [TopDecl name] -> ModuleG mname name
Module { mName :: Located mname
mName      = ModuleG mname name -> Located mname
forall mname name. ModuleG mname name -> Located mname
mName ModuleG mname name
m
                   , mInstance :: Maybe (Located ModName)
mInstance  = ModuleG mname name -> Maybe (Located ModName)
forall mname name. ModuleG mname name -> Maybe (Located ModName)
mInstance ModuleG mname name
m
                   , mDecls :: [TopDecl name]
mDecls     = [TopDecl name] -> [TopDecl name]
forall t. NoPos t => t -> t
noPos (ModuleG mname name -> [TopDecl name]
forall mname name. ModuleG mname name -> [TopDecl name]
mDecls ModuleG mname name
m)
                   }

instance NoPos (NestedModule name) where
  noPos :: NestedModule name -> NestedModule name
noPos (NestedModule ModuleG name name
m) = ModuleG name name -> NestedModule name
forall name. ModuleG name name -> NestedModule name
NestedModule (ModuleG name name -> ModuleG name name
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   -> TopLevel (Decl name) -> TopDecl name
forall name. TopLevel (Decl name) -> TopDecl name
Decl     (TopLevel (Decl name) -> TopLevel (Decl name)
forall t. NoPos t => t -> t
noPos TopLevel (Decl name)
x)
      DPrimType TopLevel (PrimType name)
t -> TopLevel (PrimType name) -> TopDecl name
forall name. TopLevel (PrimType name) -> TopDecl name
DPrimType (TopLevel (PrimType name) -> TopLevel (PrimType name)
forall t. NoPos t => t -> t
noPos TopLevel (PrimType name)
t)
      TDNewtype TopLevel (Newtype name)
n -> TopLevel (Newtype name) -> TopDecl name
forall name. TopLevel (Newtype name) -> TopDecl name
TDNewtype(TopLevel (Newtype name) -> TopLevel (Newtype name)
forall t. NoPos t => t -> t
noPos TopLevel (Newtype name)
n)
      Include Located String
x   -> Located String -> TopDecl name
forall name. Located String -> TopDecl name
Include  (Located String -> Located String
forall t. NoPos t => t -> t
noPos Located String
x)
      DParameterFun ParameterFun name
d  -> ParameterFun name -> TopDecl name
forall name. ParameterFun name -> TopDecl name
DParameterFun (ParameterFun name -> ParameterFun name
forall t. NoPos t => t -> t
noPos ParameterFun name
d)
      DParameterType ParameterType name
d -> ParameterType name -> TopDecl name
forall name. ParameterType name -> TopDecl name
DParameterType (ParameterType name -> ParameterType name
forall t. NoPos t => t -> t
noPos ParameterType name
d)
      DParameterConstraint [Located (Prop name)]
d -> [Located (Prop name)] -> TopDecl name
forall name. [Located (Prop name)] -> TopDecl name
DParameterConstraint ([Located (Prop name)] -> [Located (Prop name)]
forall t. NoPos t => t -> t
noPos [Located (Prop name)]
d)
      DModule TopLevel (NestedModule name)
d -> TopLevel (NestedModule name) -> TopDecl name
forall name. TopLevel (NestedModule name) -> TopDecl name
DModule (TopLevel (NestedModule name) -> TopLevel (NestedModule name)
forall t. NoPos t => t -> t
noPos TopLevel (NestedModule name)
d)
      DImport Located (ImportG (ImpName name))
d -> Located (ImportG (ImpName name)) -> TopDecl name
forall name. Located (ImportG (ImpName name)) -> TopDecl name
DImport (Located (ImportG (ImpName name))
-> Located (ImportG (ImpName name))
forall t. NoPos t => t -> t
noPos Located (ImportG (ImpName name))
d)


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 = Schema x -> Schema x
forall t. NoPos t => t -> t
noPos (ParameterFun x -> Schema x
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 = a -> a
forall t. NoPos t => t -> t
noPos (TopLevel a -> a
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   -> [Located name] -> Schema name -> Decl name
forall name. [Located name] -> Schema name -> Decl name
DSignature ([Located name] -> [Located name]
forall t. NoPos t => t -> t
noPos [Located name]
x) (Schema name -> Schema name
forall t. NoPos t => t -> t
noPos Schema name
y)
      DPragma    [Located name]
x Pragma
y   -> [Located name] -> Pragma -> Decl name
forall name. [Located name] -> Pragma -> Decl name
DPragma    ([Located name] -> [Located name]
forall t. NoPos t => t -> t
noPos [Located name]
x) (Pragma -> Pragma
forall t. NoPos t => t -> t
noPos Pragma
y)
      DPatBind   Pattern name
x Expr name
y   -> Pattern name -> Expr name -> Decl name
forall name. Pattern name -> Expr name -> Decl name
DPatBind   (Pattern name -> Pattern name
forall t. NoPos t => t -> t
noPos Pattern name
x) (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
y)
      DFixity Fixity
f [Located name]
ns     -> Fixity -> [Located name] -> Decl name
forall name. Fixity -> [Located name] -> Decl name
DFixity Fixity
f ([Located name] -> [Located name]
forall t. NoPos t => t -> t
noPos [Located name]
ns)
      DBind      Bind name
x     -> Bind name -> Decl name
forall name. Bind name -> Decl name
DBind      (Bind name -> Bind name
forall t. NoPos t => t -> t
noPos Bind name
x)
      DRec       [Bind name]
bs    -> [Bind name] -> Decl name
forall name. [Bind name] -> Decl name
DRec       ((Bind name -> Bind name) -> [Bind name] -> [Bind name]
forall a b. (a -> b) -> [a] -> [b]
map Bind name -> Bind name
forall t. NoPos t => t -> t
noPos [Bind name]
bs)
      DType      TySyn name
x     -> TySyn name -> Decl name
forall name. TySyn name -> Decl name
DType      (TySyn name -> TySyn name
forall t. NoPos t => t -> t
noPos TySyn name
x)
      DProp      PropSyn name
x     -> PropSyn name -> Decl name
forall name. PropSyn name -> Decl name
DProp      (PropSyn name -> PropSyn name
forall t. NoPos t => t -> t
noPos PropSyn name
x)
      DLocated   Decl name
x Range
_   -> Decl name -> Decl name
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 :: forall name.
Located name -> [TParam name] -> Rec (Type name) -> Newtype name
Newtype { nName :: Located name
nName   = Located name -> Located name
forall t. NoPos t => t -> t
noPos (Newtype name -> Located name
forall name. Newtype name -> Located name
nName Newtype name
n)
                    , nParams :: [TParam name]
nParams = Newtype name -> [TParam name]
forall name. Newtype name -> [TParam name]
nParams Newtype name
n
                    , nBody :: Rec (Type name)
nBody   = ((Range, Type name) -> (Range, Type name))
-> Rec (Type name) -> Rec (Type name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Range, Type name) -> (Range, Type name)
forall t. NoPos t => t -> t
noPos (Newtype name -> Rec (Type name)
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 :: forall name.
Located name
-> [Pattern name]
-> Located (BindDef name)
-> Maybe (Schema name)
-> Bool
-> Maybe Fixity
-> [Pragma]
-> Bool
-> Maybe Text
-> ExportType
-> Bind name
Bind { bName :: Located name
bName      = Located name -> Located name
forall t. NoPos t => t -> t
noPos (Bind name -> Located name
forall name. Bind name -> Located name
bName      Bind name
x)
                 , bParams :: [Pattern name]
bParams    = [Pattern name] -> [Pattern name]
forall t. NoPos t => t -> t
noPos (Bind name -> [Pattern name]
forall name. Bind name -> [Pattern name]
bParams    Bind name
x)
                 , bDef :: Located (BindDef name)
bDef       = Located (BindDef name) -> Located (BindDef name)
forall t. NoPos t => t -> t
noPos (Bind name -> Located (BindDef name)
forall name. Bind name -> Located (BindDef name)
bDef       Bind name
x)
                 , bSignature :: Maybe (Schema name)
bSignature = Maybe (Schema name) -> Maybe (Schema name)
forall t. NoPos t => t -> t
noPos (Bind name -> Maybe (Schema name)
forall name. Bind name -> Maybe (Schema name)
bSignature Bind name
x)
                 , bInfix :: Bool
bInfix     = Bind name -> Bool
forall name. Bind name -> Bool
bInfix Bind name
x
                 , bFixity :: Maybe Fixity
bFixity    = Bind name -> Maybe Fixity
forall name. Bind name -> Maybe Fixity
bFixity Bind name
x
                 , bPragmas :: [Pragma]
bPragmas   = [Pragma] -> [Pragma]
forall t. NoPos t => t -> t
noPos (Bind name -> [Pragma]
forall name. Bind name -> [Pragma]
bPragmas   Bind name
x)
                 , bMono :: Bool
bMono      = Bind name -> Bool
forall name. Bind name -> Bool
bMono Bind name
x
                 , bDoc :: Maybe Text
bDoc       = Bind name -> Maybe Text
forall name. Bind name -> Maybe Text
bDoc Bind name
x
                 , bExport :: ExportType
bExport    = Bind name -> ExportType
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) = Located name
-> Maybe Fixity -> [TParam name] -> Type name -> TySyn name
forall n.
Located n -> Maybe Fixity -> [TParam n] -> Type n -> TySyn n
TySyn (Located name -> Located name
forall t. NoPos t => t -> t
noPos Located name
x) Maybe Fixity
f ([TParam name] -> [TParam name]
forall t. NoPos t => t -> t
noPos [TParam name]
y) (Type name -> Type name
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) = Located name
-> Maybe Fixity -> [TParam name] -> [Prop name] -> PropSyn name
forall n.
Located n -> Maybe Fixity -> [TParam n] -> [Prop n] -> PropSyn n
PropSyn (Located name -> Located name
forall t. NoPos t => t -> t
noPos Located name
x) Maybe Fixity
f ([TParam name] -> [TParam name]
forall t. NoPos t => t -> t
noPos [TParam name]
y) ([Prop name] -> [Prop name]
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          -> name -> Expr name
forall n. n -> Expr n
EVar     name
x
      ELit Literal
x          -> Literal -> Expr name
forall n. Literal -> Expr n
ELit     Literal
x
      ENeg Expr name
x          -> Expr name -> Expr name
forall n. Expr n -> Expr n
ENeg     (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x)
      EComplement Expr name
x   -> Expr name -> Expr name
forall n. Expr n -> Expr n
EComplement (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x)
      EGenerate Expr name
x     -> Expr name -> Expr name
forall n. Expr n -> Expr n
EGenerate (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x)
      ETuple [Expr name]
x        -> [Expr name] -> Expr name
forall n. [Expr n] -> Expr n
ETuple   ([Expr name] -> [Expr name]
forall t. NoPos t => t -> t
noPos [Expr name]
x)
      ERecord Rec (Expr name)
x       -> Rec (Expr name) -> Expr name
forall n. Rec (Expr n) -> Expr n
ERecord  (((Range, Expr name) -> (Range, Expr name))
-> Rec (Expr name) -> Rec (Expr name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Range, Expr name) -> (Range, Expr name)
forall t. NoPos t => t -> t
noPos Rec (Expr name)
x)
      ESel Expr name
x Selector
y        -> Expr name -> Selector -> Expr name
forall n. Expr n -> Selector -> Expr n
ESel     (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) Selector
y
      EUpd Maybe (Expr name)
x [UpdField name]
y        -> Maybe (Expr name) -> [UpdField name] -> Expr name
forall n. Maybe (Expr n) -> [UpdField n] -> Expr n
EUpd     (Maybe (Expr name) -> Maybe (Expr name)
forall t. NoPos t => t -> t
noPos Maybe (Expr name)
x) ([UpdField name] -> [UpdField name]
forall t. NoPos t => t -> t
noPos [UpdField name]
y)
      EList [Expr name]
x         -> [Expr name] -> Expr name
forall n. [Expr n] -> Expr n
EList    ([Expr name] -> [Expr name]
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 -> Type name
-> Maybe (Type name) -> Type name -> Maybe (Type name) -> Expr name
forall n.
Type n -> Maybe (Type n) -> Type n -> Maybe (Type n) -> Expr n
EFromTo  (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) (Maybe (Type name) -> Maybe (Type name)
forall t. NoPos t => t -> t
noPos Maybe (Type name)
y) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
z) (Maybe (Type name) -> Maybe (Type name)
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
                      -> Bool
-> Type name
-> Type name
-> Type name
-> Maybe (Type name)
-> Expr name
forall n.
Bool -> Type n -> Type n -> Type n -> Maybe (Type n) -> Expr n
EFromToBy Bool
isStrict (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
z) (Maybe (Type name) -> Maybe (Type name)
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
                      -> Bool
-> Type name
-> Type name
-> Type name
-> Maybe (Type name)
-> Expr name
forall n.
Bool -> Type n -> Type n -> Type n -> Maybe (Type n) -> Expr n
EFromToDownBy Bool
isStrict (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
z) (Maybe (Type name) -> Maybe (Type name)
forall t. NoPos t => t -> t
noPos Maybe (Type name)
t)
      EFromToLessThan Type name
x Type name
y Maybe (Type name)
t -> Type name -> Type name -> Maybe (Type name) -> Expr name
forall n. Type n -> Type n -> Maybe (Type n) -> Expr n
EFromToLessThan (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y) (Maybe (Type name) -> Maybe (Type name)
forall t. NoPos t => t -> t
noPos Maybe (Type name)
t)
      EInfFrom Expr name
x Maybe (Expr name)
y    -> Expr name -> Maybe (Expr name) -> Expr name
forall n. Expr n -> Maybe (Expr n) -> Expr n
EInfFrom (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) (Maybe (Expr name) -> Maybe (Expr name)
forall t. NoPos t => t -> t
noPos Maybe (Expr name)
y)
      EComp Expr name
x [[Match name]]
y       -> Expr name -> [[Match name]] -> Expr name
forall n. Expr n -> [[Match n]] -> Expr n
EComp    (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) ([[Match name]] -> [[Match name]]
forall t. NoPos t => t -> t
noPos [[Match name]]
y)
      EApp  Expr name
x Expr name
y       -> Expr name -> Expr name -> Expr name
forall n. Expr n -> Expr n -> Expr n
EApp     (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
y)
      EAppT Expr name
x [TypeInst name]
y       -> Expr name -> [TypeInst name] -> Expr name
forall n. Expr n -> [TypeInst n] -> Expr n
EAppT    (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) ([TypeInst name] -> [TypeInst name]
forall t. NoPos t => t -> t
noPos [TypeInst name]
y)
      EIf   Expr name
x Expr name
y Expr name
z     -> Expr name -> Expr name -> Expr name -> Expr name
forall n. Expr n -> Expr n -> Expr n -> Expr n
EIf      (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
y) (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
z)
      EWhere Expr name
x [Decl name]
y      -> Expr name -> [Decl name] -> Expr name
forall n. Expr n -> [Decl n] -> Expr n
EWhere   (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) ([Decl name] -> [Decl name]
forall t. NoPos t => t -> t
noPos [Decl name]
y)
      ETyped Expr name
x Type name
y      -> Expr name -> Type name -> Expr name
forall n. Expr n -> Type n -> Expr n
ETyped   (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y)
      ETypeVal Type name
x      -> Type name -> Expr name
forall n. Type n -> Expr n
ETypeVal (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x)
      EFun FunDesc name
dsc [Pattern name]
x Expr name
y    -> FunDesc name -> [Pattern name] -> Expr name -> Expr name
forall n. FunDesc n -> [Pattern n] -> Expr n -> Expr n
EFun FunDesc name
dsc ([Pattern name] -> [Pattern name]
forall t. NoPos t => t -> t
noPos [Pattern name]
x) (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
y)
      ELocated Expr name
x Range
_    -> Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
x

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

instance NoPos (UpdField name) where
  noPos :: UpdField name -> UpdField name
noPos (UpdField UpdHow
h [Located Selector]
xs Expr name
e) = UpdHow -> [Located Selector] -> Expr name -> UpdField name
forall n. UpdHow -> [Located Selector] -> Expr n -> UpdField n
UpdField UpdHow
h [Located Selector]
xs (Expr name -> Expr name
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)   = Type name -> TypeInst name
forall name. Type name -> TypeInst name
PosInst (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
ts)
  noPos (NamedInst Named (Type name)
fs) = Named (Type name) -> TypeInst name
forall name. Named (Type name) -> TypeInst name
NamedInst (Named (Type name) -> Named (Type name)
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)  = Pattern name -> Expr name -> Match name
forall name. Pattern name -> Expr name -> Match name
Match (Pattern name -> Pattern name
forall t. NoPos t => t -> t
noPos Pattern name
x) (Expr name -> Expr name
forall t. NoPos t => t -> t
noPos Expr name
y)
  noPos (MatchLet Bind name
b) = Bind name -> Match name
forall name. Bind name -> Match name
MatchLet (Bind name -> Bind name
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       -> Located name -> Pattern name
forall n. Located n -> Pattern n
PVar    (Located name -> Located name
forall t. NoPos t => t -> t
noPos Located name
x)
      Pattern name
PWild        -> Pattern name
forall n. Pattern n
PWild
      PTuple [Pattern name]
x     -> [Pattern name] -> Pattern name
forall n. [Pattern n] -> Pattern n
PTuple  ([Pattern name] -> [Pattern name]
forall t. NoPos t => t -> t
noPos [Pattern name]
x)
      PRecord Rec (Pattern name)
x    -> Rec (Pattern name) -> Pattern name
forall n. Rec (Pattern n) -> Pattern n
PRecord (((Range, Pattern name) -> (Range, Pattern name))
-> Rec (Pattern name) -> Rec (Pattern name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Range, Pattern name) -> (Range, Pattern name)
forall t. NoPos t => t -> t
noPos Rec (Pattern name)
x)
      PList [Pattern name]
x      -> [Pattern name] -> Pattern name
forall n. [Pattern n] -> Pattern n
PList   ([Pattern name] -> [Pattern name]
forall t. NoPos t => t -> t
noPos [Pattern name]
x)
      PTyped Pattern name
x Type name
y   -> Pattern name -> Type name -> Pattern name
forall n. Pattern n -> Type n -> Pattern n
PTyped  (Pattern name -> Pattern name
forall t. NoPos t => t -> t
noPos Pattern name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y)
      PSplit Pattern name
x Pattern name
y   -> Pattern name -> Pattern name -> Pattern name
forall n. Pattern n -> Pattern n -> Pattern n
PSplit  (Pattern name -> Pattern name
forall t. NoPos t => t -> t
noPos Pattern name
x) (Pattern name -> Pattern name
forall t. NoPos t => t -> t
noPos Pattern name
y)
      PLocated Pattern name
x Range
_ -> Pattern name -> Pattern name
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
_) = [TParam name]
-> [Prop name] -> Type name -> Maybe Range -> Schema name
forall n.
[TParam n] -> [Prop n] -> Type n -> Maybe Range -> Schema n
Forall ([TParam name] -> [TParam name]
forall t. NoPos t => t -> t
noPos [TParam name]
x) ([Prop name] -> [Prop name]
forall t. NoPos t => t -> t
noPos [Prop name]
y) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
z) Maybe Range
forall a. Maybe a
Nothing

instance NoPos (TParam name) where
  noPos :: TParam name -> TParam name
noPos (TParam name
x Maybe Kind
y Maybe Range
_)  = name -> Maybe Kind -> Maybe Range -> TParam name
forall n. n -> Maybe Kind -> Maybe Range -> TParam n
TParam name
x Maybe Kind
y Maybe Range
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         -> Type name
forall n. Type n
TWild
      TUser name
x [Type name]
y     -> name -> [Type name] -> Type name
forall n. n -> [Type n] -> Type n
TUser    name
x         ([Type name] -> [Type name]
forall t. NoPos t => t -> t
noPos [Type name]
y)
      TTyApp [Named (Type name)]
x      -> [Named (Type name)] -> Type name
forall n. [Named (Type n)] -> Type n
TTyApp   ([Named (Type name)] -> [Named (Type name)]
forall t. NoPos t => t -> t
noPos [Named (Type name)]
x)
      TRecord Rec (Type name)
x     -> Rec (Type name) -> Type name
forall n. Rec (Type n) -> Type n
TRecord  (((Range, Type name) -> (Range, Type name))
-> Rec (Type name) -> Rec (Type name)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Range, Type name) -> (Range, Type name)
forall t. NoPos t => t -> t
noPos Rec (Type name)
x)
      TTuple [Type name]
x      -> [Type name] -> Type name
forall n. [Type n] -> Type n
TTuple   ([Type name] -> [Type name]
forall t. NoPos t => t -> t
noPos [Type name]
x)
      TFun Type name
x Type name
y      -> Type name -> Type name -> Type name
forall n. Type n -> Type n -> Type n
TFun     (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y)
      TSeq Type name
x Type name
y      -> Type name -> Type name -> Type name
forall n. Type n -> Type n -> Type n
TSeq     (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
y)
      Type name
TBit          -> Type name
forall n. Type n
TBit
      TNum Integer
n        -> Integer -> Type name
forall n. Integer -> Type n
TNum Integer
n
      TChar Char
n       -> Char -> Type name
forall n. Char -> Type n
TChar Char
n
      TLocated Type name
x Range
_  -> Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x
      TParens Type name
x     -> Type name -> Type name
forall name. Type name -> Type name
TParens (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x)
      TInfix Type name
x Located name
y Fixity
f Type name
z-> Type name -> Located name -> Fixity -> Type name -> Type name
forall n. Type n -> Located n -> Fixity -> Type n -> Type n
TInfix (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
x) Located name
y Fixity
f (Type name -> Type name
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) = Type name -> Prop name
forall n. Type n -> Prop n
CType (Type name -> Type name
forall t. NoPos t => t -> t
noPos Type name
t)