[GHC] #16185: Add an AnonArgFlag to FunTy
GHC
ghc-devs at haskell.org
Tue Jan 15 23:58:50 UTC 2019
#16185: Add an AnonArgFlag to FunTy
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.3
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Description changed by simonpj:
Old description:
> In Trac #15952 Richard and I agreed that it makes sense to add a flag to
> `FunTy` to distinguish `(->)` from `(=>)`. This ticket tracks progress.
>
> See [ticket:15952#comment:7] and [ticket:15952#comment:8].
>
> Main changes:
>
> * Define `AnonArgFlag` in `Var`, alongside `ArgFlag`
> {{{
> data AnonArgFlag
> = VisArg -- Used for (->): an ordinary non-dependent arrow
> -- The argument is visible in source code
> | InvisArg -- Used for (=>): a non-dependent predicate arrow
> -- The argument is invisible in source code
> }}}
>
> * `Type` looks like this
> {{{
> data Type
> = ...
>
> | FFunTy -- ^ t1 -> t2 Very common, so an important special case
> -- FFunTy for "full function type"; see pattern synonym
> for FunTy
> { ft_af :: AnonArgFlag -- Is this (->) or (=>)?
> , ft_arg :: Type -- Argument type
> , ft_res :: Type } -- Resuult type
> }}}
> I'm using a record here to anticipate Linear Haskell, which will add a
> multiplicity field to `FFunTy`.
>
> * Add a uni-directional pattern synonym for the old `FunTy`
> {{{
> pattern FunTy :: Type -> Type -> Type
> pattern FunTy arg res <- FFunTy { ft_arg = arg, ft_res = res }
> }}}
>
> Everything else follows routinely.
>
> A huge win is that `isPredTy` vanishes almost completely.
New description:
In Trac #15952 Richard and I agreed that it makes sense to add a flag to
`FunTy` to distinguish `(->)` from `(=>)`. This ticket tracks progress.
See [ticket:15952#comment:7] and [ticket:15952#comment:8].
Main changes:
* Define `AnonArgFlag` in `Var`, alongside `ArgFlag`
{{{
data AnonArgFlag
= VisArg -- Used for (->): an ordinary non-dependent arrow
-- The argument is visible in source code
| InvisArg -- Used for (=>): a non-dependent predicate arrow
-- The argument is invisible in source code
}}}
* `Type` looks like this
{{{
data Type
= ...
| FFunTy -- ^ t1 -> t2 Very common, so an important special case
-- FFunTy for "full function type"; see pattern synonym
for FunTy
{ ft_af :: AnonArgFlag -- Is this (->) or (=>)?
, ft_arg :: Type -- Argument type
, ft_res :: Type } -- Resuult type
}}}
I'm using a record here to anticipate Linear Haskell, which will add a
multiplicity field to `FFunTy`.
* Add a uni-directional pattern synonym for the old `FunTy`
{{{
pattern FunTy :: Type -> Type -> Type
pattern FunTy arg res <- FFunTy { ft_arg = arg, ft_res = res }
}}}
Everything else follows routinely.
A huge win is that `isPredTy` vanishes almost completely.
------------------
Invariant: in `FFunTy af arg res`
* If `af` = `InvisArg` then `arg :: Constraint`
* But not vice versa
When in Core-land, e.g. in the Simplifier, we often call `exprType`. What
is the type of `Lam b e`? Either a `ForAllTy` (if `b` is a type variable)
or a `FFunTy`. But what `AnonArgFlag`?
For Core, it really doesn't matter; the `AnonArgFlag` only affects the
typing of source code. And it is quite painful to call `isPredTy` to see
if the arg type is `Constraint` when the answer doesn't matter. Plus, in
Core, `Type` and `Constraint` coincide, so it seems like a dodgy thing to
do anyway.
We could try record the `AnonArgFlag` in the `Id`; but that means we'd
need to call `isPredTy` for every `Id` we construct.
So for now I propose the above invariant.
--
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/16185#comment:2>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list