fork(4) download
  1. {-# LANGUAGE ExistentialQuantification, RankNTypes #-}
  2.  
  3. data Yoba = Yoba { imya :: String }
  4. data Chislo = Chislo { vladelec :: Yoba, znachenie :: forall a. (a -> a) -> (a -> a) }
  5.  
  6.  
  7. bratecYoba = Yoba { imya = "Bolshoi" }
  8.  
  9.  
  10. pravda = const
  11. lozh = flip pravda
  12.  
  13.  
  14. class PodobnoyeChislu m where
  15. sleduyusheeChisloPozhaluista :: m -> m
  16. predydusheeChisloPozhaluista :: m -> m
  17. nolLiEto :: m -> (a -> a -> a)
  18. nol :: m
  19.  
  20. poschitayteVInteger :: m -> Integer
  21. poschitayteVInteger chislo
  22. | nolLiEto chislo True False = 0
  23. | otherwise = 1 + poschitayteVInteger (predydusheeChisloPozhaluista chislo)
  24.  
  25.  
  26. instance PodobnoyeChislu Chislo where
  27. sleduyusheeChisloPozhaluista (Chislo { vladelec = vladelec, znachenie = znachenie }) = Chislo { vladelec = vladelec, znachenie = \f x -> znachenie f (f x) }
  28. predydusheeChisloPozhaluista (Chislo { vladelec = vladelec, znachenie = znachenie }) = Chislo { vladelec = vladelec, znachenie = \f x -> znachenie (\g h -> h (g f)) (const x) id }
  29. nolLiEto (Chislo { vladelec = vladelec, znachenie = znachenie }) = znachenie (const lozh) pravda
  30. nol = Chislo { vladelec = bratecYoba, znachenie = const id }
  31.  
  32.  
  33. maksimumTrehChisel :: PodobnoyeChislu m => m -> m -> m -> String
  34. maksimumTrehChisel a b c
  35. | nolLiEto a True False && nolLiEto b True False = "Tretye"
  36. | nolLiEto a True False && nolLiEto c True False = "Vtoroye"
  37. | nolLiEto b True False && nolLiEto c True False = "Pervoye"
  38. | otherwise = maksimumTrehChisel (predydusheeChisloPozhaluista a) (predydusheeChisloPozhaluista b) (predydusheeChisloPozhaluista c)
  39.  
  40.  
  41. -- ALLOU, YOBA, MENYA SLYSHNO?
  42. odin :: Chislo
  43. odin = sleduyusheeChisloPozhaluista nol
  44. dva = sleduyusheeChisloPozhaluista odin
  45. chetyre = sleduyusheeChisloPozhaluista $ sleduyusheeChisloPozhaluista dva
  46.  
  47. main = putStrLn $ maksimumTrehChisel odin chetyre dva
Success #stdin #stdout 0.01s 3584KB
stdin
Standard input is empty
stdout
Vtoroye