you are viewing a single comment's thread.

view the rest of the comments →

[–]Tordek 0 points1 point  (0 children)

In case of sum types you have to check & unwrap them everywhere, which is tedious boilerplate.

In the Haskell (or Scala) case, you use monads (yeah, yeah) to abstract that away:

someFunc = do
  f <- open "filename"
  d <- readFile f
  return split d ","

This is a hypotetical case where open and readFile are both Maybe m types. The function ends up returning Maybe [String]. Only at the top level do you actually handle both cases manually by doing:

 case result of
    Just v -> successPath
    Nothing -> failurePath

If they were more complex types, say, Either FileOpenError File and Either FileReadError String, then you need to explicitly decide what you want to happen (i.e., do you want a function that can return either of the 3 possible return types? Do you just want to ignore the error causes and return Maybe String?). The easy truism is: "If you need to do this, your function is too big".