Issue2821.agda 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. -- Note: out of order true and false. Confuses the
  2. -- values if we mess up and compile it to a fresh
  3. -- datatype instead of Haskell Bool.
  4. data Two : Set where tt ff : Two
  5. {-# BUILTIN BOOL Two #-}
  6. {-# BUILTIN FALSE ff #-}
  7. {-# BUILTIN TRUE tt #-}
  8. -- Note: out of order nil and cons. Causes segfault
  9. -- if we mess up and compile it to a fresh datatype
  10. -- instead of Haskell lists.
  11. data List {a} (A : Set a) : Set a where
  12. _∷_ : A → List A → List A
  13. [] : List A
  14. {-# BUILTIN LIST List #-}
  15. postulate
  16. String : Set
  17. Char : Set
  18. {-# BUILTIN STRING String #-}
  19. {-# BUILTIN CHAR Char #-}
  20. primitive
  21. primStringToList : String → List Char
  22. primStringFromList : List Char → String
  23. primStringEquality : String → String → Two
  24. drop1 : {A : Set} → List A → List A
  25. drop1 (x ∷ xs) = xs
  26. drop1 [] = []
  27. postulate
  28. drop1' : List Char → List Char
  29. {-# COMPILE GHC drop1' = drop 1 #-}
  30. onList : (List Char → List Char) → String → String
  31. onList f s = primStringFromList (f (primStringToList s))
  32. postulate
  33. _==_ : String → String → Two
  34. {-# COMPILE GHC _==_ = (==) #-}
  35. show : Two → String
  36. show tt = onList drop1 "TRUE"
  37. show ff = onList drop1' "FALSE"
  38. record One : Set where
  39. {-# COMPILE GHC One = data () (()) #-}
  40. postulate IO : Set → Set
  41. {-# BUILTIN IO IO #-}
  42. {-# COMPILE GHC IO = type IO #-}
  43. {-# FOREIGN GHC import qualified Data.Text.IO #-}
  44. postulate putStrLn : String → IO One
  45. {-# COMPILE GHC putStrLn = Data.Text.IO.putStrLn #-}
  46. postulate _>>_ : IO One → IO One → IO One
  47. {-# COMPILE GHC _>>_ = (>>) #-}
  48. main : IO One
  49. main = do
  50. putStrLn (show ("foo" == "bar"))
  51. putStrLn (show ("foo" == "foo"))