{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DeriveAnyClass #-}
module Language.PureScript.AST.Declarations where
import Prelude.Compat
import Control.DeepSeq (NFData)
import Control.Monad.Identity
import Data.Aeson.TH
import qualified Data.Map as M
import Data.Set (Set)
import Data.Text (Text)
import qualified Data.List.NonEmpty as NEL
import GHC.Generics (Generic)
import Language.PureScript.AST.Binders
import Language.PureScript.AST.Literals
import Language.PureScript.AST.Operators
import Language.PureScript.AST.SourcePos
import Language.PureScript.Types
import Language.PureScript.PSString (PSString)
import Language.PureScript.Label (Label)
import Language.PureScript.Names
import Language.PureScript.Kinds
import Language.PureScript.TypeClassDictionaries
import Language.PureScript.Comments
import Language.PureScript.Environment
import qualified Language.PureScript.Bundle as Bundle
import qualified Language.PureScript.Constants as C
import qualified Text.Parsec as P
type Context = [(Ident, Type)]
data TypeSearch
= TSBefore Environment
| TSAfter
{ tsAfterIdentifiers :: [(Qualified Text, Type)]
, tsAfterRecordFields :: Maybe [(Label, Type)]
}
deriving Show
onTypeSearchTypes :: (Type -> Type) -> TypeSearch -> TypeSearch
onTypeSearchTypes f = runIdentity . onTypeSearchTypesM (Identity . f)
onTypeSearchTypesM :: (Applicative m) => (Type -> m Type) -> TypeSearch -> m TypeSearch
onTypeSearchTypesM f (TSAfter i r) = TSAfter <$> traverse (traverse f) i <*> traverse (traverse (traverse f)) r
onTypeSearchTypesM _ (TSBefore env) = pure (TSBefore env)
data SimpleErrorMessage
= ModuleNotFound ModuleName
| ErrorParsingFFIModule FilePath (Maybe Bundle.ErrorMessage)
| ErrorParsingModule P.ParseError
| MissingFFIModule ModuleName
| UnnecessaryFFIModule ModuleName FilePath
| MissingFFIImplementations ModuleName [Ident]
| UnusedFFIImplementations ModuleName [Ident]
| InvalidFFIIdentifier ModuleName Text
| CannotGetFileInfo FilePath
| CannotReadFile FilePath
| CannotWriteFile FilePath
| InfiniteType Type
| InfiniteKind Kind
| MultipleValueOpFixities (OpName 'ValueOpName)
| MultipleTypeOpFixities (OpName 'TypeOpName)
| OrphanTypeDeclaration Ident
| RedefinedIdent Ident
| OverlappingNamesInLet
| UnknownName (Qualified Name)
| UnknownImport ModuleName Name
| UnknownImportDataConstructor ModuleName (ProperName 'TypeName) (ProperName 'ConstructorName)
| UnknownExport Name
| UnknownExportDataConstructor (ProperName 'TypeName) (ProperName 'ConstructorName)
| ScopeConflict Name [ModuleName]
| ScopeShadowing Name (Maybe ModuleName) [ModuleName]
| DeclConflict Name Name
| ExportConflict (Qualified Name) (Qualified Name)
| DuplicateModule ModuleName
| DuplicateTypeClass (ProperName 'ClassName) SourceSpan
| DuplicateInstance Ident SourceSpan
| DuplicateTypeArgument Text
| InvalidDoBind
| InvalidDoLet
| CycleInDeclaration Ident
| CycleInTypeSynonym (Maybe (ProperName 'TypeName))
| CycleInModules [ModuleName]
| NameIsUndefined Ident
| UndefinedTypeVariable (ProperName 'TypeName)
| PartiallyAppliedSynonym (Qualified (ProperName 'TypeName))
| EscapedSkolem Text (Maybe SourceSpan) Type
| TypesDoNotUnify Type Type
| KindsDoNotUnify Kind Kind
| ConstrainedTypeUnified Type Type
| OverlappingInstances (Qualified (ProperName 'ClassName)) [Type] [Qualified Ident]
| NoInstanceFound Constraint
| AmbiguousTypeVariables Type Constraint
| UnknownClass (Qualified (ProperName 'ClassName))
| PossiblyInfiniteInstance (Qualified (ProperName 'ClassName)) [Type]
| CannotDerive (Qualified (ProperName 'ClassName)) [Type]
| InvalidDerivedInstance (Qualified (ProperName 'ClassName)) [Type] Int
| ExpectedTypeConstructor (Qualified (ProperName 'ClassName)) [Type] Type
| InvalidNewtypeInstance (Qualified (ProperName 'ClassName)) [Type]
| MissingNewtypeSuperclassInstance (Qualified (ProperName 'ClassName)) (Qualified (ProperName 'ClassName)) [Type]
| UnverifiableSuperclassInstance (Qualified (ProperName 'ClassName)) (Qualified (ProperName 'ClassName)) [Type]
| CannotFindDerivingType (ProperName 'TypeName)
| DuplicateLabel Label (Maybe Expr)
| DuplicateValueDeclaration Ident
| ArgListLengthsDiffer Ident
| OverlappingArgNames (Maybe Ident)
| MissingClassMember Ident
| ExtraneousClassMember Ident (Qualified (ProperName 'ClassName))
| ExpectedType Type Kind
| IncorrectConstructorArity (Qualified (ProperName 'ConstructorName)) Int Int
| ExprDoesNotHaveType Expr Type
| PropertyIsMissing Label
| AdditionalProperty Label
| TypeSynonymInstance
| OrphanInstance Ident (Qualified (ProperName 'ClassName)) (Set ModuleName) [Type]
| InvalidNewtype (ProperName 'TypeName)
| InvalidInstanceHead Type
| TransitiveExportError DeclarationRef [DeclarationRef]
| TransitiveDctorExportError DeclarationRef (ProperName 'ConstructorName)
| ShadowedName Ident
| ShadowedTypeVar Text
| UnusedTypeVar Text
| WildcardInferredType Type Context
| HoleInferredType Text Type Context TypeSearch
| MissingTypeDeclaration Ident Type
| OverlappingPattern [[Binder]] Bool
| IncompleteExhaustivityCheck
| MisleadingEmptyTypeImport ModuleName (ProperName 'TypeName)
| ImportHidingModule ModuleName
| UnusedImport ModuleName
| UnusedExplicitImport ModuleName [Name] (Maybe ModuleName) [DeclarationRef]
| UnusedDctorImport ModuleName (ProperName 'TypeName) (Maybe ModuleName) [DeclarationRef]
| UnusedDctorExplicitImport ModuleName (ProperName 'TypeName) [ProperName 'ConstructorName] (Maybe ModuleName) [DeclarationRef]
| DuplicateSelectiveImport ModuleName
| DuplicateImport ModuleName ImportDeclarationType (Maybe ModuleName)
| DuplicateImportRef Name
| DuplicateExportRef Name
| IntOutOfRange Integer Text Integer Integer
| ImplicitQualifiedImport ModuleName ModuleName [DeclarationRef]
| ImplicitQualifiedImportReExport ModuleName ModuleName [DeclarationRef]
| ImplicitImport ModuleName [DeclarationRef]
| HidingImport ModuleName [DeclarationRef]
| CaseBinderLengthDiffers Int [Binder]
| IncorrectAnonymousArgument
| InvalidOperatorInBinder (Qualified (OpName 'ValueOpName)) (Qualified Ident)
| CannotGeneralizeRecursiveFunction Ident Type
| CannotDeriveNewtypeForData (ProperName 'TypeName)
| ExpectedWildcard (ProperName 'TypeName)
| CannotUseBindWithDo Ident
| ClassInstanceArityMismatch Ident (Qualified (ProperName 'ClassName)) Int Int
| UserDefinedWarning Type
| UnusableDeclaration Ident [[Text]]
| CannotDefinePrimModules ModuleName
| MixedAssociativityError (NEL.NonEmpty (Qualified (OpName 'AnyOpName), Associativity))
| NonAssociativeError (NEL.NonEmpty (Qualified (OpName 'AnyOpName)))
deriving (Show)
data ErrorMessageHint
= ErrorUnifyingTypes Type Type
| ErrorInExpression Expr
| ErrorInModule ModuleName
| ErrorInInstance (Qualified (ProperName 'ClassName)) [Type]
| ErrorInSubsumption Type Type
| ErrorCheckingAccessor Expr PSString
| ErrorCheckingType Expr Type
| ErrorCheckingKind Type
| ErrorCheckingGuard
| ErrorInferringType Expr
| ErrorInApplication Expr Type Expr
| ErrorInDataConstructor (ProperName 'ConstructorName)
| ErrorInTypeConstructor (ProperName 'TypeName)
| ErrorInBindingGroup (NEL.NonEmpty Ident)
| ErrorInDataBindingGroup [ProperName 'TypeName]
| ErrorInTypeSynonym (ProperName 'TypeName)
| ErrorInValueDeclaration Ident
| ErrorInTypeDeclaration Ident
| ErrorInTypeClassDeclaration (ProperName 'ClassName)
| ErrorInForeignImport Ident
| ErrorSolvingConstraint Constraint
| PositionedError (NEL.NonEmpty SourceSpan)
deriving (Show)
data HintCategory
= ExprHint
| KindHint
| CheckHint
| PositionHint
| SolverHint
| OtherHint
deriving (Show, Eq)
data ErrorMessage = ErrorMessage
[ErrorMessageHint]
SimpleErrorMessage
deriving (Show)
data Module = Module SourceSpan [Comment] ModuleName [Declaration] (Maybe [DeclarationRef])
deriving (Show)
getModuleName :: Module -> ModuleName
getModuleName (Module _ _ name _ _) = name
getModuleSourceSpan :: Module -> SourceSpan
getModuleSourceSpan (Module ss _ _ _ _) = ss
getModuleDeclarations :: Module -> [Declaration]
getModuleDeclarations (Module _ _ _ declarations _) = declarations
addDefaultImport :: Qualified ModuleName -> Module -> Module
addDefaultImport (Qualified toImportAs toImport) m@(Module ss coms mn decls exps) =
if isExistingImport `any` decls || mn == toImport then m
else Module ss coms mn (ImportDeclaration (ss, []) toImport Implicit toImportAs : decls) exps
where
isExistingImport (ImportDeclaration _ mn' _ as')
| mn' == toImport =
case toImportAs of
Nothing -> True
_ -> as' == toImportAs
isExistingImport _ = False
importPrim :: Module -> Module
importPrim =
let
primModName = C.Prim
in
addDefaultImport (Qualified (Just primModName) primModName)
. addDefaultImport (Qualified Nothing primModName)
data DeclarationRef
= TypeRef SourceSpan (ProperName 'TypeName) (Maybe [ProperName 'ConstructorName])
| TypeOpRef SourceSpan (OpName 'TypeOpName)
| ValueRef SourceSpan Ident
| ValueOpRef SourceSpan (OpName 'ValueOpName)
| TypeClassRef SourceSpan (ProperName 'ClassName)
| TypeInstanceRef SourceSpan Ident
| ModuleRef SourceSpan ModuleName
| KindRef SourceSpan (ProperName 'KindName)
| ReExportRef SourceSpan ModuleName DeclarationRef
deriving (Show, Generic, NFData)
instance Eq DeclarationRef where
(TypeRef _ name dctors) == (TypeRef _ name' dctors') = name == name' && dctors == dctors'
(TypeOpRef _ name) == (TypeOpRef _ name') = name == name'
(ValueRef _ name) == (ValueRef _ name') = name == name'
(ValueOpRef _ name) == (ValueOpRef _ name') = name == name'
(TypeClassRef _ name) == (TypeClassRef _ name') = name == name'
(TypeInstanceRef _ name) == (TypeInstanceRef _ name') = name == name'
(ModuleRef _ name) == (ModuleRef _ name') = name == name'
(KindRef _ name) == (KindRef _ name') = name == name'
(ReExportRef _ mn ref) == (ReExportRef _ mn' ref') = mn == mn' && ref == ref'
_ == _ = False
compDecRef :: DeclarationRef -> DeclarationRef -> Ordering
compDecRef (TypeRef _ name _) (TypeRef _ name' _) = compare name name'
compDecRef (TypeOpRef _ name) (TypeOpRef _ name') = compare name name'
compDecRef (ValueRef _ ident) (ValueRef _ ident') = compare ident ident'
compDecRef (ValueOpRef _ name) (ValueOpRef _ name') = compare name name'
compDecRef (TypeClassRef _ name) (TypeClassRef _ name') = compare name name'
compDecRef (TypeInstanceRef _ ident) (TypeInstanceRef _ ident') = compare ident ident'
compDecRef (ModuleRef _ name) (ModuleRef _ name') = compare name name'
compDecRef (KindRef _ name) (KindRef _ name') = compare name name'
compDecRef (ReExportRef _ name _) (ReExportRef _ name' _) = compare name name'
compDecRef ref ref' = compare
(orderOf ref) (orderOf ref')
where
orderOf :: DeclarationRef -> Int
orderOf TypeClassRef{} = 0
orderOf TypeOpRef{} = 1
orderOf TypeRef{} = 2
orderOf ValueRef{} = 3
orderOf ValueOpRef{} = 4
orderOf KindRef{} = 5
orderOf _ = 6
declRefSourceSpan :: DeclarationRef -> SourceSpan
declRefSourceSpan (TypeRef ss _ _) = ss
declRefSourceSpan (TypeOpRef ss _) = ss
declRefSourceSpan (ValueRef ss _) = ss
declRefSourceSpan (ValueOpRef ss _) = ss
declRefSourceSpan (TypeClassRef ss _) = ss
declRefSourceSpan (TypeInstanceRef ss _) = ss
declRefSourceSpan (ModuleRef ss _) = ss
declRefSourceSpan (KindRef ss _) = ss
declRefSourceSpan (ReExportRef ss _ _) = ss
declRefName :: DeclarationRef -> Name
declRefName (TypeRef _ n _) = TyName n
declRefName (TypeOpRef _ n) = TyOpName n
declRefName (ValueRef _ n) = IdentName n
declRefName (ValueOpRef _ n) = ValOpName n
declRefName (TypeClassRef _ n) = TyClassName n
declRefName (TypeInstanceRef _ n) = IdentName n
declRefName (ModuleRef _ n) = ModName n
declRefName (KindRef _ n) = KiName n
declRefName (ReExportRef _ _ ref) = declRefName ref
getTypeRef :: DeclarationRef -> Maybe (ProperName 'TypeName, Maybe [ProperName 'ConstructorName])
getTypeRef (TypeRef _ name dctors) = Just (name, dctors)
getTypeRef _ = Nothing
getTypeOpRef :: DeclarationRef -> Maybe (OpName 'TypeOpName)
getTypeOpRef (TypeOpRef _ op) = Just op
getTypeOpRef _ = Nothing
getValueRef :: DeclarationRef -> Maybe Ident
getValueRef (ValueRef _ name) = Just name
getValueRef _ = Nothing
getValueOpRef :: DeclarationRef -> Maybe (OpName 'ValueOpName)
getValueOpRef (ValueOpRef _ op) = Just op
getValueOpRef _ = Nothing
getTypeClassRef :: DeclarationRef -> Maybe (ProperName 'ClassName)
getTypeClassRef (TypeClassRef _ name) = Just name
getTypeClassRef _ = Nothing
getKindRef :: DeclarationRef -> Maybe (ProperName 'KindName)
getKindRef (KindRef _ name) = Just name
getKindRef _ = Nothing
isModuleRef :: DeclarationRef -> Bool
isModuleRef ModuleRef{} = True
isModuleRef _ = False
data ImportDeclarationType
= Implicit
| Explicit [DeclarationRef]
| Hiding [DeclarationRef]
deriving (Eq, Show)
isImplicit :: ImportDeclarationType -> Bool
isImplicit Implicit = True
isImplicit _ = False
isExplicit :: ImportDeclarationType -> Bool
isExplicit (Explicit _) = True
isExplicit _ = False
data TypeDeclarationData = TypeDeclarationData
{ tydeclSourceAnn :: !SourceAnn
, tydeclIdent :: !Ident
, tydeclType :: !Type
} deriving (Show, Eq)
overTypeDeclaration :: (TypeDeclarationData -> TypeDeclarationData) -> Declaration -> Declaration
overTypeDeclaration f d = maybe d (TypeDeclaration . f) (getTypeDeclaration d)
getTypeDeclaration :: Declaration -> Maybe TypeDeclarationData
getTypeDeclaration (TypeDeclaration d) = Just d
getTypeDeclaration _ = Nothing
unwrapTypeDeclaration :: TypeDeclarationData -> (Ident, Type)
unwrapTypeDeclaration td = (tydeclIdent td, tydeclType td)
data ValueDeclarationData a = ValueDeclarationData
{ valdeclSourceAnn :: !SourceAnn
, valdeclIdent :: !Ident
, valdeclName :: !NameKind
, valdeclBinders :: ![Binder]
, valdeclExpression :: !a
} deriving (Show, Functor, Foldable, Traversable)
overValueDeclaration :: (ValueDeclarationData [GuardedExpr] -> ValueDeclarationData [GuardedExpr]) -> Declaration -> Declaration
overValueDeclaration f d = maybe d (ValueDeclaration . f) (getValueDeclaration d)
getValueDeclaration :: Declaration -> Maybe (ValueDeclarationData [GuardedExpr])
getValueDeclaration (ValueDeclaration d) = Just d
getValueDeclaration _ = Nothing
pattern ValueDecl :: SourceAnn -> Ident -> NameKind -> [Binder] -> [GuardedExpr] -> Declaration
pattern ValueDecl sann ident name binders expr
= ValueDeclaration (ValueDeclarationData sann ident name binders expr)
data Declaration
= DataDeclaration SourceAnn DataDeclType (ProperName 'TypeName) [(Text, Maybe Kind)] [(ProperName 'ConstructorName, [Type])]
| DataBindingGroupDeclaration (NEL.NonEmpty Declaration)
| TypeSynonymDeclaration SourceAnn (ProperName 'TypeName) [(Text, Maybe Kind)] Type
| TypeDeclaration {-# UNPACK #-} !TypeDeclarationData
| ValueDeclaration {-# UNPACK #-} !(ValueDeclarationData [GuardedExpr])
| BoundValueDeclaration SourceAnn Binder Expr
| BindingGroupDeclaration (NEL.NonEmpty ((SourceAnn, Ident), NameKind, Expr))
| ExternDeclaration SourceAnn Ident Type
| ExternDataDeclaration SourceAnn (ProperName 'TypeName) Kind
| ExternKindDeclaration SourceAnn (ProperName 'KindName)
| FixityDeclaration SourceAnn (Either ValueFixity TypeFixity)
| ImportDeclaration SourceAnn ModuleName ImportDeclarationType (Maybe ModuleName)
| TypeClassDeclaration SourceAnn (ProperName 'ClassName) [(Text, Maybe Kind)] [Constraint] [FunctionalDependency] [Declaration]
| TypeInstanceDeclaration SourceAnn [Ident] Integer Ident [Constraint] (Qualified (ProperName 'ClassName)) [Type] TypeInstanceBody
deriving (Show)
data ValueFixity = ValueFixity Fixity (Qualified (Either Ident (ProperName 'ConstructorName))) (OpName 'ValueOpName)
deriving (Eq, Ord, Show)
data TypeFixity = TypeFixity Fixity (Qualified (ProperName 'TypeName)) (OpName 'TypeOpName)
deriving (Eq, Ord, Show)
pattern ValueFixityDeclaration :: SourceAnn -> Fixity -> Qualified (Either Ident (ProperName 'ConstructorName)) -> OpName 'ValueOpName -> Declaration
pattern ValueFixityDeclaration sa fixity name op = FixityDeclaration sa (Left (ValueFixity fixity name op))
pattern TypeFixityDeclaration :: SourceAnn -> Fixity -> Qualified (ProperName 'TypeName) -> OpName 'TypeOpName -> Declaration
pattern TypeFixityDeclaration sa fixity name op = FixityDeclaration sa (Right (TypeFixity fixity name op))
data TypeInstanceBody
= DerivedInstance
| NewtypeInstance
| NewtypeInstanceWithDictionary Expr
| ExplicitInstance [Declaration]
deriving (Show)
mapTypeInstanceBody :: ([Declaration] -> [Declaration]) -> TypeInstanceBody -> TypeInstanceBody
mapTypeInstanceBody f = runIdentity . traverseTypeInstanceBody (Identity . f)
traverseTypeInstanceBody :: (Applicative f) => ([Declaration] -> f [Declaration]) -> TypeInstanceBody -> f TypeInstanceBody
traverseTypeInstanceBody f (ExplicitInstance ds) = ExplicitInstance <$> f ds
traverseTypeInstanceBody _ other = pure other
declSourceAnn :: Declaration -> SourceAnn
declSourceAnn (DataDeclaration sa _ _ _ _) = sa
declSourceAnn (DataBindingGroupDeclaration ds) = declSourceAnn (NEL.head ds)
declSourceAnn (TypeSynonymDeclaration sa _ _ _) = sa
declSourceAnn (TypeDeclaration td) = tydeclSourceAnn td
declSourceAnn (ValueDeclaration vd) = valdeclSourceAnn vd
declSourceAnn (BoundValueDeclaration sa _ _) = sa
declSourceAnn (BindingGroupDeclaration ds) = let ((sa, _), _, _) = NEL.head ds in sa
declSourceAnn (ExternDeclaration sa _ _) = sa
declSourceAnn (ExternDataDeclaration sa _ _) = sa
declSourceAnn (ExternKindDeclaration sa _) = sa
declSourceAnn (FixityDeclaration sa _) = sa
declSourceAnn (ImportDeclaration sa _ _ _) = sa
declSourceAnn (TypeClassDeclaration sa _ _ _ _ _) = sa
declSourceAnn (TypeInstanceDeclaration sa _ _ _ _ _ _ _) = sa
declSourceSpan :: Declaration -> SourceSpan
declSourceSpan = fst . declSourceAnn
declName :: Declaration -> Maybe Name
declName (DataDeclaration _ _ n _ _) = Just (TyName n)
declName (TypeSynonymDeclaration _ n _ _) = Just (TyName n)
declName (ValueDeclaration vd) = Just (IdentName (valdeclIdent vd))
declName (ExternDeclaration _ n _) = Just (IdentName n)
declName (ExternDataDeclaration _ n _) = Just (TyName n)
declName (ExternKindDeclaration _ n) = Just (KiName n)
declName (FixityDeclaration _ (Left (ValueFixity _ _ n))) = Just (ValOpName n)
declName (FixityDeclaration _ (Right (TypeFixity _ _ n))) = Just (TyOpName n)
declName (TypeClassDeclaration _ n _ _ _ _) = Just (TyClassName n)
declName (TypeInstanceDeclaration _ _ _ n _ _ _ _) = Just (IdentName n)
declName ImportDeclaration{} = Nothing
declName BindingGroupDeclaration{} = Nothing
declName DataBindingGroupDeclaration{} = Nothing
declName BoundValueDeclaration{} = Nothing
declName TypeDeclaration{} = Nothing
isValueDecl :: Declaration -> Bool
isValueDecl ValueDeclaration{} = True
isValueDecl _ = False
isDataDecl :: Declaration -> Bool
isDataDecl DataDeclaration{} = True
isDataDecl TypeSynonymDeclaration{} = True
isDataDecl _ = False
isImportDecl :: Declaration -> Bool
isImportDecl ImportDeclaration{} = True
isImportDecl _ = False
isExternDataDecl :: Declaration -> Bool
isExternDataDecl ExternDataDeclaration{} = True
isExternDataDecl _ = False
isExternKindDecl :: Declaration -> Bool
isExternKindDecl ExternKindDeclaration{} = True
isExternKindDecl _ = False
isFixityDecl :: Declaration -> Bool
isFixityDecl FixityDeclaration{} = True
isFixityDecl _ = False
getFixityDecl :: Declaration -> Maybe (Either ValueFixity TypeFixity)
getFixityDecl (FixityDeclaration _ fixity) = Just fixity
getFixityDecl _ = Nothing
isExternDecl :: Declaration -> Bool
isExternDecl ExternDeclaration{} = True
isExternDecl _ = False
isTypeClassInstanceDeclaration :: Declaration -> Bool
isTypeClassInstanceDeclaration TypeInstanceDeclaration{} = True
isTypeClassInstanceDeclaration _ = False
isTypeClassDeclaration :: Declaration -> Bool
isTypeClassDeclaration TypeClassDeclaration{} = True
isTypeClassDeclaration _ = False
flattenDecls :: [Declaration] -> [Declaration]
flattenDecls = concatMap flattenOne
where flattenOne :: Declaration -> [Declaration]
flattenOne (DataBindingGroupDeclaration decls) = concatMap flattenOne decls
flattenOne d = [d]
data Guard = ConditionGuard Expr
| PatternGuard Binder Expr
deriving (Show)
data GuardedExpr = GuardedExpr [Guard] Expr
deriving (Show)
pattern MkUnguarded :: Expr -> GuardedExpr
pattern MkUnguarded e = GuardedExpr [] e
data Expr
= Literal SourceSpan (Literal Expr)
| UnaryMinus SourceSpan Expr
| BinaryNoParens Expr Expr Expr
| Parens Expr
| Accessor PSString Expr
| ObjectUpdate Expr [(PSString, Expr)]
| ObjectUpdateNested Expr (PathTree Expr)
| Abs Binder Expr
| App Expr Expr
| Var SourceSpan (Qualified Ident)
| Op SourceSpan (Qualified (OpName 'ValueOpName))
| IfThenElse Expr Expr Expr
| Constructor SourceSpan (Qualified (ProperName 'ConstructorName))
| Case [Expr] [CaseAlternative]
| TypedValue Bool Expr Type
| Let WhereProvenance [Declaration] Expr
| Do [DoNotationElement]
| Ado [DoNotationElement] Expr
| TypeClassDictionaryConstructorApp (Qualified (ProperName 'ClassName)) Expr
| TypeClassDictionary Constraint
(M.Map (Maybe ModuleName) (M.Map (Qualified (ProperName 'ClassName)) (M.Map (Qualified Ident) NamedDict)))
[ErrorMessageHint]
| TypeClassDictionaryAccessor (Qualified (ProperName 'ClassName)) Ident
| DeferredDictionary (Qualified (ProperName 'ClassName)) [Type]
| AnonymousArgument
| Hole Text
| PositionedValue SourceSpan [Comment] Expr
deriving (Show)
data WhereProvenance
= FromWhere
| FromLet
deriving (Show)
data CaseAlternative = CaseAlternative
{
caseAlternativeBinders :: [Binder]
, caseAlternativeResult :: [GuardedExpr]
} deriving (Show)
data DoNotationElement
= DoNotationValue Expr
| DoNotationBind Binder Expr
| DoNotationLet [Declaration]
| PositionedDoNotationElement SourceSpan [Comment] DoNotationElement
deriving (Show)
newtype PathTree t = PathTree (AssocList PSString (PathNode t))
deriving (Show, Eq, Ord, Functor, Foldable, Traversable)
data PathNode t = Leaf t | Branch (PathTree t)
deriving (Show, Eq, Ord, Functor, Foldable, Traversable)
newtype AssocList k t = AssocList { runAssocList :: [(k, t)] }
deriving (Show, Eq, Ord, Foldable, Functor, Traversable)
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''DeclarationRef)
$(deriveJSON (defaultOptions { sumEncoding = ObjectWithSingleField }) ''ImportDeclarationType)
isTrueExpr :: Expr -> Bool
isTrueExpr (Literal _ (BooleanLiteral True)) = True
isTrueExpr (Var _ (Qualified (Just (ModuleName [ProperName "Prelude"])) (Ident "otherwise"))) = True
isTrueExpr (Var _ (Qualified (Just (ModuleName [ProperName "Data", ProperName "Boolean"])) (Ident "otherwise"))) = True
isTrueExpr (TypedValue _ e _) = isTrueExpr e
isTrueExpr (PositionedValue _ _ e) = isTrueExpr e
isTrueExpr _ = False