File: TH_repGuard.hs

package info (click to toggle)
haskell-ghc-exactprint 1.7.1.0-1
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,044 kB
  • sloc: haskell: 32,076; makefile: 7
file content (35 lines) | stat: -rw-r--r-- 637 bytes parent folder | download | duplicates (3)
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
{-# LANGUAGE TemplateHaskell #-}
module Main
where

import Language.Haskell.TH
import System.IO

$(
  do ds <- [d|
        foo :: Int -> Int
        foo x
         | x == 5 = 6
        foo x = 7
      |]
     runIO $ do { putStrLn (pprint ds); hFlush stdout }
     return ds
 )

$(
  do ds <- [d|
        bar :: Maybe Int -> Int
        bar x
         | Just y <- x = y
        bar _ = 9
      |]
     runIO $ do { putStrLn (pprint ds) ; hFlush stdout }
     return ds
 )

main :: IO ()
main = do putStrLn $ show $ foo 5
          putStrLn $ show $ foo 8
          putStrLn $ show $ bar (Just 2)
          putStrLn $ show $ bar Nothing