How to make specialized type classes for certain types, default implementation for the rest of types
问题 I would like to have a type class of types that can possibly casted to other types when possible. class Castable a b where cast :: a -> Maybe b cast _ = Nothing -- default implementation Now the class would be implemented for some types and for all the others I would like to have default implementation. How one can do that? 回答1: It's not necessarily a safe or Haskell-y thing to do, but it is certainly possible, using OverlappingInstances First, enable them: {-# LANGUAGE MultiParamTypeClasses