Skip to content

Instantly share code, notes, and snippets.

@kseo
Created February 13, 2016 03: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 kseo/7637a293ad468a9f6f0b to your computer and use it in GitHub Desktop.
Save kseo/7637a293ad468a9f6f0b to your computer and use it in GitHub Desktop.
An example of type family
{-# LANGUAGE TypeFamilies #-}
class Graph g where
type Vertex g
data Edge g
src, tgt :: Edge g -> Vertex g
outEdges :: g -> Vertex g -> [Edge g]
newtype G1 = G1 [Edge G1]
instance Graph G1 where
type Vertex G1 = Int
data Edge G1 = MkEdge1 (Vertex G1) (Vertex G1)
src = undefined
tgt = undefined
outEdges = undefined
newtype G2 = G2 [Edge G2]
instance Graph G2 where
type Vertex G2 = String
data Edge G2 = MkEdge2 Int (Vertex G2) (Vertex G2)
src = undefined
tgt = undefined
outEdges = undefined
neighbours g v = map tgt (outEdges g v)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment