[Haskell-cafe] newbie type signature question

Bulat Ziganshin bulat.ziganshin at gmail.com
Tue Jun 13 02:22:52 EDT 2006


Hello Brian,

Tuesday, June 13, 2006, 1:11:37 AM, you wrote:

>> data UTF8Stream h = (ByteStream h) => UTF8Stream h
>>
>> instance TextStream (UTF8Stream h) ...
>>
>> addUTF8Encoding :: h -> (UTF8Stream h)
>>
>> and so on. currently i should add type constraint to each and every
>> class and function i declared.

> Hello Bulat -
> Thanks for the example. Afaiu, if you don't write any type signature at all,
> type inference will infer the constraint,

of course, but

1) it is considered as bad programming style
2) haddock currently can't infer function types
3) it doesn't work for class headers
4) functions that create UTF8Stream don't use ByteStream functions

> Or perhaps there could be a special syntax to indicate a partial type
> signature, that the compiler would complete by adding the contexts eg:

>       f ::: Set a -> a
>         ^^^ ? 3 colons to indicate that the compiler will add the relevant
> context(s)

partial signatures is also among the proposals for future Haskell, and
Oleg has technique to make partial signatures even in H98

>> i don't tried using existential types

> Yes I also think they'd be slower

Simon Marlow once said it can be faster. i don't know details, though.
something like the dictionaries for my types are constructed on each
call (?), while dictionaries for existential type constructed only
once, on the moment of encapsulation



-- 
Best regards,
 Bulat                            mailto:Bulat.Ziganshin at gmail.com



More information about the Haskell-Cafe mailing list