Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys,

I'm somewhat new to Haskell and I'm stuck with the following.

I have this type:

C++
newtype Node = N (String,[Edge])
newtype Graph = G([Node])
n2s (N (n,e)) = n


How come I can't use:
C++
n2s :: Node -> String
n2s n = fst n


If n is a tuple then you should be able to do this right?

Whenever I do this I get the following error:

Couldn't match expected type '<string,b0>' with actual type 'Node'.

Any ideas?

Also the following doesn't work. Same error:
VB
edges (G([])) = []
edges (G(n:ns)) = snd n ++ edges (G(ns))



Thanks in advance
Posted
Updated 7-Mar-13 4:10am
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900