Advertisement
mbazs

coq1

Aug 8th, 2020
2,714
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Module Test.
  2.  
  3. Inductive day : Type :=
  4.   | monday
  5.   | tuesday
  6.   | wednesday
  7.   | thursday
  8.   | friday
  9.   | saturday
  10.   | sunday.
  11.  
  12. Definition next_weekday (d:day) : day :=
  13.   match d with
  14.   | monday => tuesday
  15.   | tuesday => wednesday
  16.   | wednesday => thursday
  17.   | thursday => friday
  18.   | friday => monday
  19.   | saturday => monday
  20.   | sunday => monday
  21.   end.
  22.  
  23. Definition prev_weekday (d:day) : day :=
  24.   match d with
  25.   | monday => friday
  26.   | tuesday => monday
  27.   | wednesday => tuesday
  28.   | thursday => wednesday
  29.   | friday => thursday
  30.   | saturday => friday
  31.   | sunday => friday
  32.   end.
  33.  
  34. Example test_next_weekday:
  35.   next_weekday (next_weekday saturday) = tuesday.
  36. Proof. simpl. reflexivity. Qed.
  37.  
  38. Example test_prev_weekday:
  39.   prev_weekday (prev_weekday saturday) = thursday.
  40. Proof. simpl. reflexivity. Qed.
  41.  
  42. End Test.
  43.  
  44. Require Extraction.
  45. Extraction Language Haskell.
  46. Recursive Extraction Test.
  47.  
  48.  
  49.  ----> After compilation to Haskell <----
  50.  
  51.  
  52. module Main where
  53.  
  54. import qualified Prelude
  55.  
  56. data Day =
  57.    Monday
  58.  | Tuesday
  59.  | Wednesday
  60.  | Thursday
  61.  | Friday
  62.  | Saturday
  63.  | Sunday
  64.  
  65. day_rect :: a1 -> a1 -> a1 -> a1 -> a1 -> a1 -> a1 -> Day -> a1
  66. day_rect f f0 f1 f2 f3 f4 f5 d =
  67.   case d of {
  68.    Monday -> f;
  69.    Tuesday -> f0;
  70.    Wednesday -> f1;
  71.    Thursday -> f2;
  72.    Friday -> f3;
  73.    Saturday -> f4;
  74.    Sunday -> f5}
  75.  
  76. day_rec :: a1 -> a1 -> a1 -> a1 -> a1 -> a1 -> a1 -> Day -> a1
  77. day_rec =
  78.   day_rect
  79.  
  80. next_weekday :: Day -> Day
  81. next_weekday d =
  82.   case d of {
  83.    Monday -> Tuesday;
  84.    Tuesday -> Wednesday;
  85.    Wednesday -> Thursday;
  86.    Thursday -> Friday;
  87.    _ -> Monday}
  88.  
  89. prev_weekday :: Day -> Day
  90. prev_weekday d =
  91.   case d of {
  92.    Tuesday -> Monday;
  93.    Wednesday -> Tuesday;
  94.    Thursday -> Wednesday;
  95.    Friday -> Thursday;
  96.    _ -> Friday}
  97.  
  98.  
  99.  
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement