{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
module Futhark.Representation.AST.Attributes.Patterns
(
paramIdent
, paramType
, paramDeclType
, patElemIdent
, patElemType
, setPatElemLore
, patternElements
, patternIdents
, patternContextIdents
, patternValueIdents
, patternNames
, patternValueNames
, patternContextNames
, patternTypes
, patternValueTypes
, patternExtTypes
, patternSize
, basicPattern
)
where
import Futhark.Representation.AST.Syntax
import Futhark.Representation.AST.Attributes.Types
(existentialiseExtTypes, staticShapes, Typed(..), DeclTyped(..))
paramType :: Typed attr => ParamT attr -> Type
paramType = typeOf
paramDeclType :: DeclTyped attr => ParamT attr -> DeclType
paramDeclType = declTypeOf
paramIdent :: Typed attr => ParamT attr -> Ident
paramIdent param = Ident (paramName param) (typeOf param)
patElemIdent :: Typed attr => PatElemT attr -> Ident
patElemIdent pelem = Ident (patElemName pelem) (typeOf pelem)
patElemType :: Typed attr => PatElemT attr -> Type
patElemType = typeOf
setPatElemLore :: PatElemT oldattr -> newattr -> PatElemT newattr
setPatElemLore pe x = fmap (const x) pe
patternElements :: PatternT attr -> [PatElemT attr]
patternElements pat = patternContextElements pat ++ patternValueElements pat
patternIdents :: Typed attr => PatternT attr -> [Ident]
patternIdents pat = patternContextIdents pat ++ patternValueIdents pat
patternContextIdents :: Typed attr => PatternT attr -> [Ident]
patternContextIdents = map patElemIdent . patternContextElements
patternValueIdents :: Typed attr => PatternT attr -> [Ident]
patternValueIdents = map patElemIdent . patternValueElements
patternNames :: PatternT attr -> [VName]
patternNames = map patElemName . patternElements
patternContextNames :: PatternT attr -> [VName]
patternContextNames = map patElemName . patternContextElements
patternValueNames :: PatternT attr -> [VName]
patternValueNames = map patElemName . patternValueElements
patternTypes :: Typed attr => PatternT attr -> [Type]
patternTypes = map identType . patternIdents
patternValueTypes :: Typed attr => PatternT attr -> [Type]
patternValueTypes = map identType . patternValueIdents
patternExtTypes :: Typed attr => PatternT attr -> [ExtType]
patternExtTypes pat =
existentialiseExtTypes (patternContextNames pat)
(staticShapes (patternValueTypes pat))
patternSize :: PatternT attr -> Int
patternSize (Pattern context values) = length context + length values
basicPattern :: [Ident] -> [Ident] -> PatternT Type
basicPattern context values =
Pattern (map patElem context) (map patElem values)
where patElem (Ident name t) = PatElem name t