summaryrefslogtreecommitdiff
path: root/testsuite/tests/simplCore/should_compile/str-rules.hs
blob: a94df9958c1b417dc71de50dc9d7cc830b161d51 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{-# LANGUAGE MagicHash #-}
import GHC.CString (unpackFoldrCString#, unpackCString#)
import GHC.Base (eqString)
main :: IO ()
main = do
  let mix c n = fromEnum c + n
  n <- readLn

  print $
    -- We expect the two literals to be concatenated, resulting in "@@@ ab"
    unpackFoldrCString# "@@@ a"# mix
      (unpackFoldrCString# "b"# mix n)

  if eqString (unpackCString# "x"#) (unpackCString# "y"#)
    then putStrLn $ unpackCString# "@@@ c"# -- this should be optimized out
    else putStrLn $ unpackCString# "@@@ d"#

  if eqString (unpackCString# "foo"#) (unpackCString# "foo"#)
    then putStrLn $ unpackCString# "@@@ e"#
    else putStrLn $ unpackCString# "@@@ f"# -- this should be optimized out