[Haskell-beginners] matching the output of a standard function to my
function definition (non-exhaustive pattern problem)
martin.tomko at geo.uzh.ch
Mon Sep 27 11:41:24 EDT 2010
I am sure this is a very beginner problem, but I am not sure how to
I have a myFunct function:
myFunct :: Int -> [a] -> a
myFunct _  = error "empty list provided as arg"
myFunct a [b] | length [x|x<-[b],fid x == a] == 0 = error "no match"
| otherwise = head [x|x<-[b],fid x == a]
Which works fine (may not be elegant, but works). Now, I am chaining it
in a larger function, where at some stage I use a graph object from
Data.Graph and check for its edges, resulting in [(Int,Int)]
trying to run this fails:
myFunct (fst (head (edges graph))) myList
*** Exception: FunctStruct.hs:(136,1)-(138,48): Non-exhaustive patterns
in function myFunct
contrived example, but myList is a list of [a]). The problem arrises
from the definition of the type of Edge as (Vertex,Vertex), but type
Vertex = Int
so that should be ok, or am I making a mistake somewhere and I should go
from vertex to Integer explicitly?
Thanks a lot!
More information about the Beginners