Khan Saab
Khan Saab

Reputation: 511

Nested case expression and indentation error

I want to use nested case-expressions so i tried to write this code and i am stucked here from last 2 hours and can't figure out why is it giving me error on the last line.

getAdjacency :: [Node a] -> Map.Map k v -> Map.Map k v
getAdjacency matched adjacency = matched >>= (\(x,y,d) -> do
   case (Map.lookup y adjacency) of
                   Nothing -> Map.insert y (x,d) adjacency
                   Just ((nod,value)) ->
                                      case ((d + distance) < value) of
                                        True -> (Map.insert y (x,d+distance) adjacency)
                                        False -> (Map.insert y (nod,value) adjacency)

It says parse error(Possible indentation error or mismatched brackets)

What is wrong in the last line?

Upvotes: 0

Views: 288

Answers (1)

Gurkenglas
Gurkenglas

Reputation: 2317

You didn't close the ( to the left of \(x,y,d). Decent editors will highlight the bracket that corresponds to the bracket at your cursor, or color brackets in pairs, which helps to debug the mismatched bracket error.

Consider using https://hackage.haskell.org/package/containers-0.5.10.2/docs/Data-Map-Strict.html#v:alter for your use case.

Upvotes: 2

Related Questions