[Haskell-cafe] Random thoughts about typeclasses

Robert Clausecker fuzxxl at gmail.com
Mon May 16 14:10:37 CEST 2011


Hello!

I found out, that GHC implements typeclasses as an extra argument, a
record that stores all functions of the typeclass. So I was wondering,
is there a way (apart from using newtype) to pass a custom record as the
typeclass record, to modify the behavior of the typeclass? I thought
about something like this:

    f :: Show a => [a] -> String
    f = (>>= show)

    -- So, f becomes something like this?
    __f :: ClassShow a -> [a] -> String
    __f (ClassShow __show) x = x >>= __show

    -- And if I call the function, it looks somewhat like this:
    g :: [Int] -> String
    g = f

    __g = __f instanceShowInt

    -- But is it possible to do something like this?
    g2 = __f (ClassShow (return . fromEnum))

Tis is just a random thought, some compilers like JHC implement them by
another way. But would this theoretically be possible?

Yours, FUZxxl




More information about the Haskell-Cafe mailing list