{-|
Module : 1JC3-Assign3.Assign_3.hs
Copyright : (c) Curtis D’Alves 2021
License : GPL (see the LICENSE file)
Maintainer : none
Stability : experimental
Portability : portable
Description:
Assignment 3 – McMaster CS 1JC3 2021
-}
module Assign_3 where
———————————————————————————————————–
— INSTRUCTIONS README!!!
———————————————————————————————————–
— 1) DO NOT DELETE/ALTER ANY CODE ABOVE THESE INSTRUCTIONS
— 2) DO NOT REMOVE / ALTER TYPE DECLERATIONS (I.E THE LINE WITH THE :: ABOUT THE FUNCTION DECLERATION)
— IF YOU ARE UNABLE TO COMPLETE A FUNCTION, LEAVE IT’S ORIGINAL IMPLEMENTATION (I.E. THROW AN ERROR)
— 3) MAKE SURE THE PROJECT COMPILES (I.E. RUN STACK BUILD AND MAKE SURE THERE ARE NO ERRORS) BEFORE
— SUBMITTING, FAILURE TO DO SO WILL RESULT IN A MARK OF 0
— 4) REPLACE macid = “TODO” WITH YOUR ACTUAL MACID (EX. IF YOUR MACID IS jim THEN macid = “jim”)
———————————————————————————————————–
— Name: TODO add name
— Date: TODO add date
macid :: String
macid = “TODO”
{- —————————————————————–
– Datatypes
– —————————————————————–
-}
data Graph a = Graph { getNodes :: [Node a]
, getEdges :: [Edge] }
deriving (Show,Eq)
type Edge = (NodeID,NodeID)
type NodeID = Int
data Node a = Node { getNodeID :: NodeID,
getNodeVal :: a }
deriving (Show,Eq,Ord)
{- —————————————————————–
– Example Graph
– —————————————————————–
– —– ———-
– | A |——->| C | |
– —– —– <---
- | |
- | ------|
- v |
- ----- <-|
- | B |
- -----
-}
nodeA,nodeB,nodeC :: Node Char
nodeA = Node 0 'A'
nodeB = Node 1 'B'
nodeC = Node 2 'C'
exGraph :: Graph Char
exGraph =
let
nodes = [nodeA,nodeB,nodeC]
edges = [(0,1),(0,2),(2,2),(2,1)]
in Graph nodes edges
{- -----------------------------------------------------------------
- maxNodeID
- -----------------------------------------------------------------
- Description:
- TODO add comments
-}
maxNodeID :: Graph a -> Maybe NodeID
maxNodeID graph = error “TODO implement maxNodeID”
{- —————————————————————–
– insertNode
– —————————————————————–
– Description:
– TODO add comments
-}
insertNode :: a -> Graph a -> Graph a
insertNode v graph = error “TODO implement insertNode”
{- —————————————————————–
– removeNode
– —————————————————————–
– Description:
– TODO add comments
-}
removeNode :: NodeID -> Graph a -> Graph a
removeNode nID graph = error “TODO implement removeNode”
{- —————————————————————–
– lookupNode
– —————————————————————–
– Description:
– TODO add comments
-}
lookupNode :: NodeID -> Graph a -> Maybe (Node a)
lookupNode nID graph = error “TODO implement lookupNode”
{- —————————————————————–
– insertEdge
– —————————————————————–
– Description:
– TODO add comments
-}
insertEdge :: Eq a => (NodeID,NodeID) -> Graph a -> Maybe (Graph a)
insertEdge _ (Graph [] _) = Nothing
insertEdge (n1,n2) (Graph ns es)
| not containsBothNodes = error “TODO implement insertEdge”
| containsEdge = error “TODO implement insertEdge”
| otherwise = error “TODO implement insertEdge”
where
containsBothNodes :: Bool
containsBothNodes = error “TODO implement containsBothNodes”
containsEdge :: Bool
containsEdge = error “TODO implement containsEdge”