[Haskell-beginners] Associated data type confusion

Alex Hammel ahammel87 at gmail.com
Mon Jan 12 19:25:54 UTC 2015

Hello list,

I've got a collection of types which come from generated code (it's
protocol buffer stuff). I'd like to write a polymorphic function which maps
the protocol buffer generated data types to native data types. I've tried
something like this:

class FromProto a where
    type InputDataType
    fromProto :: InputDataType -> a

instance ToProto SomeNativeType where
    type OutputDataType = SomeGeneratedType
    toProto =
        {- etc -}

instance FromProto SomeOtherNativeType where
    type InputDataType = SomeOtherGeneratedType
    fromProto =
        {- etc -}

Which works fine for mapping one native data type to *one* generated data
type, but breaks when I want to define different *InputDataType*s for
different instances of *FromProto*.

I feel like I'm making this more complicated than I need to. Is there an
easy way to get the data type to data type mapping that I'm looking for?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150112/b9fd9377/attachment.html>

More information about the Beginners mailing list