Getting rid of a Graph keyword in Haskell -
i have data type :
data node = node { label :: a, adjacent :: [(a,int)] } deriving (show, eq) data network = graph [node a] deriving (show, eq) i have function turns graph list of nodes :
degraph :: ([node a] -> network a) -> [node a] -> [node a] degraph _ x = x example : main> degraph graph [ ( node 'a' [ ( 'b' , 3 ) , ( 'c' ,2 ) ] ) , ( node 'b' [ ('c' , 3 ) ] ) , ( node 'c' [] ) ] [node {label = 'a', adjacent = [('b',3),('c',2)]},node {label = 'b', adjacent = [('c',3)]},node {label = 'c', adjacent = []}] but when use function inside function :
func1 (graph x) = degraph (graph x) i error :
error "./network.hs":14 - type error in application * expression : degraph (graph x) term : graph x type : network b * not match : [node a] -> network a
can tell me how can solve problem?
your degraph function has 2 arguments , returns second of two.
you want instead:
degraph :: network -> [node a] degraph (graph x) = x the call degraph in ghci works because forgot put parentheses around graph , following list, it's call 2 arguments. in func1, (correctly) use parentheses, type error, because you're inconsistent.
Comments
Post a Comment