Haskell: min distance between neighbor numbers on a list -
I am trying to define a factbook which finds a minimum distance between neighboring numbers on a list
Something like this:
Minneobresadence [2,3,6,2,0,1,9,8] => 1 My code looks like this:
minNeighborsDistance [] = [] minNeighborsDistance (x: xs) = minimum [minNeighborsDistance xs ++ [subtract Although it starts running, once I enter a list, I get an exception error. I am new to Haskell. Any help in this case
Ol>
This will not match [] in the first line. , Then This will successfully match (x: xs) to specify a value for x and xs Forward, since you call the empty MinNeighborsDistance recursively, you are Mesa will call it on a single list, except that when you pass it empty list.
Comments
Post a Comment