I have defined a couple of type synonyms as follows:
type Potential = Float
type Label = String
type LabelSet = [String]
In addition I have defined the following type and type synonym:
data VariableNode = VariableNode Label Potential LabelSet
type PGM = [VariableNode]
Finally, the following function to construct a graph:
makePGM :: [((Label, Potential), LabelSet)] -> PGM
makePGM (x:xs) = (VariableNode (fst . fst x) (snd . fst x) (snd x)) : makePGM xs
makePGM [] = []
In the above function, a list of tuples is provided where the first element of the tuple is another tuple and the second a list, as per the functions type signature.
I am new to Haskell so am having some difficulty in deciphering the following error messages:
Prelude> :l Graph.hs
[1 of 1] Compiling Graph ( Graph.hs, interpreted )
Graph.hs:14:33: error:
• Couldn't match type ‘a0 -> c0’ with ‘[Char]’
Expected type: Label
Actual type: a0 -> c0
• Probable cause: ‘(.)’ is applied to too few arguments
In the first argument of ‘VariableNode’, namely ‘(fst . fst x)’
In the first argument of ‘(:)’, namely
‘(VariableNode (fst . fst x) (snd . fst x) (snd x))’
In the expression:
(VariableNode (fst . fst x) (snd . fst x) (snd x)) : makePGM xs
Graph.hs:14:39: error:
• Couldn't match expected type ‘a0 -> (c0, b0)’
with actual type ‘(Label, Potential)’
• Possible cause: ‘fst’ is applied to too many arguments
In the second argument of ‘(.)’, namely ‘fst x’
In the first argument of ‘VariableNode’, namely ‘(fst . fst x)’
In the first argument of ‘(:)’, namely
‘(VariableNode (fst . fst x) (snd . fst x) (snd x))’
Graph.hs:14:47: error:
• Couldn't match type ‘a1 -> c1’ with ‘Float’
Expected type: Potential
Actual type: a1 -> c1
• Probable cause: ‘(.)’ is applied to too few arguments
In the second argument of ‘VariableNode’, namely ‘(snd . fst x)’
In the first argument of ‘(:)’, namely
‘(VariableNode (fst . fst x) (snd . fst x) (snd x))’
In the expression:
(VariableNode (fst . fst x) (snd . fst x) (snd x)) : makePGM xs
Graph.hs:14:53: error:
• Couldn't match expected type ‘a1 -> (a2, c1)’
with actual type ‘(Label, Potential)’
• Possible cause: ‘fst’ is applied to too many arguments
In the second argument of ‘(.)’, namely ‘fst x’
In the second argument of ‘VariableNode’, namely ‘(snd . fst x)’
In the first argument of ‘(:)’, namely
‘(VariableNode (fst . fst x) (snd . fst x) (snd x))’
Failed, modules loaded: none.
I have concluded that there are type mismatches but am not clear how so, given the types I have defined and the functions type signature.
.by$(both occurrences)? - Ruud Helderman\y -> fst (fst x) yif you inline the definition of(.). If you wanted to use function composition there, it could be done with something like(fst . fst) x, but at that point it's getting pretty verbose. - CarlmakePGM (x:xs) = (VariableNode (fst . fst $ x) (snd . fst $ x) (snd x)) : makePGM xs. In haskell, function application happens before composition, so you need to be explicit so that it happens in the intended order here. - Erik