Alexander Solla wrote: > Doing similar constructions with type classes is possible. I think you > might have to use witness types (or even a nice functorial wrapper > around your target value in the original algebra, or both) to do > generalizations of type classes. For example: > > class Uneditable obj where > a :: a -> obj > b :: b -> obj > > class Refactored obj witness where > a' :: Maybe (a -> obj) > b' :: Maybe (a -> obj) > > data EmptyFilter -- I think the name of the extension needed for this is > 'EmptyDataDecls' > data NoA > data NoB > > instance Uneditable obj => Refactored obj EmptyFilter where a' = Just a; > b' = Just b > instance Uneditable obj => Refactored obj NoA where a' = Nothing; b' = > Just b Alexander, Thank you for your excellent explanation and example. Due to my lack of knowledge, I do not fully understand what is going in the example.
I had a look at the types of a and a’. *Main> :t a a :: forall a obj. (Uneditable obj) => a -> obj *Main> :t a' a' :: forall witness a obj. (Refactored obj witness) => Maybe (a -> obj) Could you explain the example a little more. Apologies for my slowness. Pat This message has been scanned for content and viruses by the DIT Information Services E-Mail Scanning Service, and is believed to be clean. http://www.dit.ie _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe