PrintBool.agda 779 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. module PrintBool where
  2. open import Common.IO
  3. open import Common.Bool
  4. open import Common.Char
  5. open import Common.List
  6. open import Common.Unit
  7. open import Common.String
  8. isNewline : Char -> Bool
  9. isNewline '\n' = true
  10. isNewline _ = false
  11. sequence : {A : Set} -> List (IO A) -> IO (List A)
  12. sequence [] = return []
  13. sequence (x ∷ xs) =
  14. r <- x ,
  15. rs <- sequence xs ,
  16. return (r ∷ rs)
  17. mapM : {A B : Set} -> (A -> IO B) -> List A -> IO (List B)
  18. mapM f xs = sequence (map f xs)
  19. printList : List Char -> IO Unit
  20. printList xs =
  21. mapM printChar xs ,,
  22. printChar '\n'
  23. main : IO Unit
  24. main =
  25. printChar 'a' ,,
  26. printList ('a' ∷ 'b' ∷ 'c' ∷ []) ,,
  27. putStrLn "printBool" ,,
  28. printBool (isNewline '\n') ,,
  29. printBool (isNewline 'a') ,,
  30. return unit