Created
February 13, 2016 03:45
-
-
Save kseo/7637a293ad468a9f6f0b to your computer and use it in GitHub Desktop.
An example of type family
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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