[Haskell-cafe] partial type annotations

Nicholas Tung ntung at ntung.com
Thu Jan 19 21:37:28 CET 2012

Dear all,

    I wanted to voice support for a partial type annotations. Here's my
usage scenario: I have a monad for an imperative EDSL, which has an
associated expression data type,

class (Monad m, Expression (ExprTyp m)) => MyDSLMonad m where
    data ExprTyp m :: * -> *

    and you write imperative EDSL code like so,

my_code_block = do
    x <- instruction1
    y <- instruction2 (x + x)

    I want the user to be able to annotate "x is an Integer". However, to
do that now, one has to now add a type signature for my_code_block like so,
so that the $m$ variable is in scope,

my_code_block :: forall m. MyDSLMonad m => m ()
my_code_block = do
    x :: ExprTyp m Integer <- instruction1

    If such a feature were available, one could write a nice type synonym
"Expr" and use it like so,

type Expr a = ExprTyp _ a

my_code_block = do
    x :: Expr Integer <- instruction1

    Suggestions for workarounds are appreciated. I created an
`asExprTypeOf`, similar to Prelude's `asExprTyp`, but I don't like the
syntax as much.

    Some previous discussion
* http://www.haskell.org/pipermail/haskell/2002-April/009409.html
* (a reply) http://www.haskell.org/pipermail/haskell/2002-April/009413.html
* http://hackage.haskell.org/trac/haskell-prime/wiki/PartialTypeAnnotations

Nicholas — https://ntung.com — 4432-nstung
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120119/f36eda54/attachment.htm>

More information about the Haskell-Cafe mailing list