packages feed

retrie-2.0.0: tests/inputs/CPP.test

# Copyright (c) 2025 Andrew Farmer
# Copyright (c) 2020-2024 Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
#
--adhoc "forall f g xs. map f (map g xs) = map (f . g) xs"
-u CPP.otherthing
--adhoc "forall a b. a * b = mul a b"
--pattern-backward CPP.One
-u CPP.baz
-u CPP.baz2
===
 {-# LANGUAGE CPP #-}
 {-# LANGUAGE PatternSynonyms #-}
 module CPP where

 #define TRUE 1

 infixr 0 $

 main :: IO ()
 main = print $ foo (bar [1..10])

 foo :: Int -> Int
 foo x = x - 2

 #if TRUE
 bar :: [Int] -> Int
 bar ys = length (filter even zs)
   where
-    zs = map (+1) (map (*3) ys)
+    zs = map ((+1) . (*3)) ys
 #endif

 pattern One :: a -> [a]
 pattern One y = y : []

 #if TRUE
 fixityExpr :: Int -> Int -> Int -> Int
-fixityExpr x y w = x + y * w
+fixityExpr x y w = x + mul y w

 fixityPat :: [Int] -> Int
-fixityPat (x : y : []) = x
+fixityPat (x : One y) = x

 fixityExpr3 :: (Int -> Int) -> Int -> Int -> Int -> Int
-fixityExpr3 f p q z = f $ p + q * z
+fixityExpr3 f p q z = f $ p + mul q z

 fixityPat3 :: [Int] -> Int
-fixityPat3 ( a  :   b    :     c      :       d        :         []) = a
+fixityPat3 ( a  :   b    :     c      :       One d) = a
 #endif

 #if TRUE
 bar2 :: [Int] -> Int
 bar2 ys = length (filter even zs)
   where
-    zs = map (+2) (map (*3) ys)
+    zs = map ((+2) . (*3)) ys
 #else
 bar2 :: [Int] -> Int
 bar2 ys = length (filter even zs)
   where
-    zs = map (+2) (map (*4) ys)
+    zs = map ((+2) . (*4)) ys

 otherthing :: Maybe a -> Int
 otherthing mb = case mb of
   Just{} -> 1
   Nothing -> 0

 useit :: Int
-useit = otherthing (Just 54)
+useit = case Just 54 of
+         Just{} -> 1
+         Nothing -> 0

 #if TRUE
 useit2 :: Int
-useit2 = otherthing (Just 42)
+useit2 = case Just 42 of
+          Just{} -> 1
+          Nothing -> 0
 #endif
 #endif

 anns :: IO ()
-anns = print [baz, pred baz, baz]
+anns = print [succ 4, pred (succ 4), succ 4]

 baz :: Int
 baz = succ 4

 baz2 :: Int
 baz2 =
   -- one
   1

-comment = baz2
+comment = -- one
+          1