Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE DataKinds, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses
- , ScopedTypeVariables, TypeApplications, TypeFamilies, UndecidableInstances
- #-}
- module Overlap2 where
- import Data.Monoid ((<>))
- data ViewP (a :: ViewR) = ViewP
- data ViewR = Default | Overload
- type family ViewF a :: ViewR where
- ViewF (a, b) = 'Overload
- ViewF a = 'Default
- class View a (r :: ViewR) where
- view' :: a -> ViewP r -> String
- instance Show a => View a 'Default where
- view' = const . show
- instance forall a b. (View a (ViewF a), View b (ViewF b)) => View (a, b) 'Overload where
- view' (x, y) _ = "(" <> view x <> ", " <> view y <> ")"
- view :: forall a. (View a (ViewF a)) => a -> String
- view x = view' x (ViewP @(ViewF a))
Add Comment
Please, Sign In to add comment