You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

15 lines
490 B

  1. And now we can do sanity checks:
  2. \begin{haskellcode}
  3. calcSomething :: Int -> MaybeInt
  4. calcSomething x
  5. | x < 100 = NoError (x * 5)
  6. | otherwise = Error "Int out of range!"
  7. \end{haskellcode}
  8. \pause
  9. And pattern match on it as well:
  10. \begin{haskellcode}
  11. addIntToList :: MaybeInt -> [Int]
  12. addIntToList (NoError x) = [x]
  13. addIntToList (Error str) = []
  14. \end{haskellcode}
  15. So if we got an error, we just return an empty list, otherwise we return a list with the \hinline{Int} as its only element.