summaryrefslogtreecommitdiff
path: root/testsuite/tests/quotes/T20893.hs
blob: 079a23166c32ea6e3e6b180a5430a94ed7eea6cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- #20893

{-# LANGUAGE LambdaCase #-}

module Main where

import Language.Haskell.TH
import Language.Haskell.TH.Ppr

main = do
  runQ t1 >>= p
  runQ t2 >>= p
  runQ t3 >>= p
  runQ t4 >>= p

t1 = [d| main = do { case 0 of { 0 -> 1 }; putStrLn "pass" } |]

t2 = [d|
      main = do
         let day = "mon"
         let num = case day of
               "mon" -> 0
               "tue" -> 1
               "wed" -> 3
               "thu" -> 4
               "fri" -> 5
               "sat" -> 6
               "sun" -> 7
               _ -> 8
         putStrLn (show day) ++ " is " (show num)
      |]

t3 = [d|
      main = do
         let color = "red"
         let id = 1
         print_color (color, id)
       where print_color (c, i) = putStrLn (c ++ " is " ++ (show i))
      |]

t4 = [d|
      main = do
         let colors = ["red", "green", "blue"]
         let ids = map (\case
                           "red" -> 0
                           "green" -> 1
                           "blue" -> 2) colors
         putStrLn (show ids)
      |]

p = putStrLn . pprint