[Haskell-cafe] partial type annotations

Aleksey Khudyakov alexey.skladnoy at gmail.com
Thu Jan 19 22:16:00 CET 2012


On 20.01.2012 00:37, Nicholas Tung wrote:
> 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,
>
I wanted such extension more than once. For me it's useful when compiler 
can almost infer type and only few type variables are actually required. 
Now I have to either type full signature or invert functions a la `asTypeOf'



> 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

Actually it should be

 > my_code_block :: ...
 > my_code_block = do
 >   x :: Integer <- instruction1 -- Require ScopedTypeVariables

or

 >   x <- instruction1 :: Expr Integer

or with partial type signatures

 >   x <- instruction1 :: _ _ Integer

or wiht

 >   x <- instruction1
 >   y <- instrunctio2 (x + x :: Integer)



More information about the Haskell-Cafe mailing list