Skip to content

Instantly share code, notes, and snippets.

@shoooe
Created June 2, 2014 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shoooe/3b563b6c99d4fb05fc76 to your computer and use it in GitHub Desktop.
Save shoooe/3b563b6c99d4fb05fc76 to your computer and use it in GitHub Desktop.
Just let it stay here for a while.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
import Data.Map (Map)
import Data.List (intersperse)
import qualified Data.Map as Map
class Renderable a where
render :: a -> String
instance Renderable Char where
render c = [c]
instance (Renderable a) => Renderable [a] where
render l = concat . intersperse " " . map render $ l
instance (Renderable k, Renderable v) => Renderable (Map k v) where
render m =
let fn k v s = concat [s, render k, ": ", render v, "\n"]
in Map.foldrWithKey fn "" m
instance (Show a) => Renderable a where
render = show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment