Restricted Data Types

Bulat Ziganshin bulatz at
Wed Feb 8 04:54:50 EST 2006

Hello Simon,

Tuesday, February 07, 2006, 7:36:23 PM, you wrote:

SPJ> | data Eq a => Set a = Set (List a)
SPJ> | 
SPJ> | that is a sort of extension i will be glad to see. in my Streams
SPJ> | library, it's a typical beast and i forced to move all these contexts
SPJ> | to the instances/functions definitions:

SPJ> Another reasonable alternative is

SPJ>         data Set a = Eq a => Set (List a)

sorry, i don't know much about all these intrinsics. all that i need
as an ordinal programmer is just to define constraints to some type's
parameters at the place where this type declared, instead of copying
these resctrictions to declarations of all the fucntions/instances
that uses this type directly or indirectly. how we can say that
Haskell supports ADTs if these restrictions should be copied even to
modules that uses this type and don't want to know anything about its
internal limitations?!


data BufferedStream h  =  BufferedStream h (Ptr ())
bufferStream :: (Stream h) => h -> IO (BufferedStream h)
instance (Stream h) => Stream (BufferedStream h)

import BufferedStream
data Database h = Database (BufferedStream h)
                           (Map String FilePos)
createDatabase :: (Stream h) => h -> IO (Database h)
instance (Stream h) => DatabaseInterface (Database h)

and so on, so on. why i should multiply this context declaration
without end? all what i really need is just one more syntax sugar -
please allow me to write this context just one time and then any use
"BufferedStream h" should enforce that 'h' belongs to the "Stream"
class. automagically.

btw, this is one more method to decrease differences between types and
classes. if "Stream" was a type, then requirement that 'h' have type
"Stream" can be easily encoded in the definition of "BufferedStream".
i want to make Haskell more class-friendly language because i know how
to use this power and the proposed desugaring is one more step in this

of course, my next proposal will be syntax-desugaring of

data BufferedStream  =  BufferedStream Stream (Ptr ())
data BufferedStream h  =  (Stream h) => BufferedStream h (Ptr ())


the same applies to the code like this:

(x::Show) <- return "xx"
print x

as i shown in the Java-like example, there is the way to express such
restrictions even in current GHC implementation. the question is only
in desugaring this neat form to the following:

return "xx" >>= ((\x -> print x) :: Show a => a -> IO ())

Best regards,
 Bulat                            mailto:bulatz at

More information about the Haskell-prime mailing list