clash-lib-1.8.4: Clash: a functional hardware description language - As a library

Copyright | (C) 2021 QBayLogic B.V.
License | BSD2 (see the file LICENSE)
Maintainer | QBayLogic B.V. <devops@qbaylogic.com>
Safe Haskell | None
Language | Haskell2010

Clash.Core.HasType

Description

Utility class to extract type information from data which has a type.

Synopsis

- class HasType a where
  - coreTypeOf :: a -> Type
- coreKindOf :: HasType a => a -> Kind
- class InferType a where
  - inferCoreTypeOf :: TyConMap -> a -> Type
- inferCoreKindOf :: InferType a => TyConMap -> a -> Kind
- applyTypeToArgs :: Term -> TyConMap -> Type -> [Either Term Type] -> Type
- piResultTy :: HasCallStack => TyConMap -> Type -> Type -> Type
- piResultTys :: HasCallStack => TyConMap -> Type -> [Type] -> Type

# Documentation

class HasType a where Source #

Methods

coreTypeOf :: a -> Type Source #

#### Instances

Instances details

HasType DataCon Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: DataCon -> Type Source #
HasType Literal Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: Literal -> Type Source #
HasType PrimInfo Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: PrimInfo -> Type Source #
HasType TyCon Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: TyCon -> Type Source #
HasType Type Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: Type -> Type Source #
HasType (Var a) Source # |
Instance details Defined in Clash.Core.HasType Methods coreTypeOf :: Var a -> Type Source #

coreKindOf :: HasType a => a -> Kind Source #

class InferType a where Source #

Methods

inferCoreTypeOf :: TyConMap -> a -> Type Source #

#### Instances

Instances details

InferType Value Source # |
Instance details Defined in Clash.Core.Evaluator.Types Methods inferCoreTypeOf :: TyConMap -> Value -> Type Source #
InferType Term Source # |
Instance details Defined in Clash.Core.HasType Methods inferCoreTypeOf :: TyConMap -> Term -> Type Source #
InferType Type Source # |
Instance details Defined in Clash.Core.HasType Methods inferCoreTypeOf :: TyConMap -> Type -> Type Source #

inferCoreKindOf :: InferType a => TyConMap -> a -> Kind Source #

applyTypeToArgs Source #

Arguments

:: Term | The complete term, used for error messages.
-> TyConMap |
-> Type |
-> [Either Term Type] |
-> Type |

Get the result type of a polymorphic function given a list of arguments

piResultTy :: HasCallStack => TyConMap -> Type -> Type -> Type Source #

Like `piResultTys`, but only applies a single type. If multiple types are being applied use `piResultTys`, as it is more efficient to only substitute once with many types.

piResultTys :: HasCallStack => TyConMap -> Type -> [Type] -> Type Source #

`(piResultTys f_ty [ty1, ..., tyn])` gives the type of `(f ty1 .. tyn)` where `f :: f_ty`

`piResultTys` is interesting because:

1. `f_ty` may have more foralls than there are args
2. Less obviously, it may have fewer foralls

Fore case 2. think of:

piResultTys (forall a . a) [forall b.b, Int]

This really can happen, such as situations involving `undefined`s type:

undefined :: forall a. a

undefined (forall b. b -> b) Int

This term should have the type `(Int -> Int)`, but notice that there are more type args than foralls in `undefined`s type.

For efficiency reasons, when there are no foralls, we simply drop arrows from a function type/kind.