[GHC] #14718: Add Boolean type families to 'base' package

GHC ghc-devs at haskell.org
Thu Jan 25 11:44:48 UTC 2018


#14718: Add Boolean type families to 'base' package
-------------------------------------+-------------------------------------
        Reporter:  chshersh          |                Owner:  (none)
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Core Libraries    |              Version:  8.5
      Resolution:                    |             Keywords:  base, type
                                     |  families, Bool
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 chshersh:

Old description:

> Sometimes you want type families to perform type level computation with
> booleans.
> Specifically:
> {{{#!hs
> type family If (p :: Bool) (ifTrue :: k) (ifFalse :: k) :: k where ...
> type family (a :: Bool) && (b :: Bool) :: Bool where ...
> type family (a :: Bool) || (b :: Bool) :: Bool where ...
> type family Not (a :: Bool) :: Bool where
> }}}
>
> Similar to existing module
> [https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Bool.html
> Data.Bool] in `base` package for boolean expressions.
>
> There's not a single package with such type families for type-level
> boolean computations. Even if it exists it probably would very small. And
> as a library author you probably don't wan extra dependencies for your
> package because cost of adding new dependency for your project is much
> bigger than cost of adding module to existing dependencies (if it's
> possible of course).
>
> It seems to me that such operations are kinda basic. And they just
> promote behavior of already existed expression-level functions to type
> level. And we already have type families for `Integer`, `Natural` and
> `String` (aka `Symbol`) and several type families returning `Bool` (`==`,
> `<=?`) in `base`. So I propose to add couple useful utilities to operate
> with `Bool` explicitly.

New description:

 Sometimes you want type families to perform type level computation with
 booleans.
 Specifically:
 {{{#!hs
 type family If (p :: Bool) (ifTrue :: k) (ifFalse :: k) :: k where ...
 type family (a :: Bool) && (b :: Bool) :: Bool where ...
 type family (a :: Bool) || (b :: Bool) :: Bool where ...
 type family Not (a :: Bool) :: Bool where
 }}}

 Similar to existing module
 [https://hackage.haskell.org/package/base-4.10.1.0/docs/Data-Bool.html
 Data.Bool] in `base` package for boolean expressions.

 There's not a single package with such type families for type-level
 boolean computations. Even if it exists it probably would very small. And
 as a library author you probably don't wan extra dependencies for your
 package because cost of adding new dependency for your project is much
 bigger than cost of adding module to existing dependencies (if it's
 possible of course).

 It seems to me that such operations are kinda basic. And they just promote
 behavior of already existed expression-level functions to type level. And
 we already have type families for `Integer`, `Natural` and `String` (aka
 `Symbol`) and several type families returning `Bool` (`==`, `<=?`) in
 `base`. So I propose to add couple useful utilities to operate with `Bool`
 explicitly.

 If this proposal approved I'm willing to contribute to `ghc`!

--

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/14718#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list