[Haskell-cafe] partial type annotations

Nicholas Tung ntung at ntung.com
Fri Jan 20 00:54:06 CET 2012


On Thu, Jan 19, 2012 at 13:16, Aleksey Khudyakov
<alexey.skladnoy at gmail.com>wrote:

> 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)
>

It's not important, but my example was what I meant -- I am creating an
EDSL, and the values flowing through are actually syntax trees representing
expressions. For example, "x + x" might create a tree with top node "+",
and subtrees as "x". We then have type

instruction1 :: m (ExprTyp m Integer)

or using the shorthand, if there were partial signatures,

instruction1 :: m (Expr Integer)

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


More information about the Haskell-Cafe mailing list