Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cabal only

  • Loading branch information...
commit b2179208290ef8fad338ca8454d3422d6ab5dfcd 1 parent 1c362da
Scott Lawrence authored May 22, 2012
3  .gitignore
... ...
@@ -1,5 +1,2 @@
1  
-*.hi
2  
-*.o
3  
-main
4 1
 .*.swp
5 2
 dist
8  Makefile
... ...
@@ -1,8 +0,0 @@
1  
-all: main
2  
-
3  
-main: main.hs Text/Format.hs
4  
-	ghc -W --make $@
5  
-
6  
-clean:
7  
-	${RM} main *.o *.hi */*.o */*.hi
8  
-
37  main.hs
... ...
@@ -1,37 +0,0 @@
1  
-module Main where
2  
-
3  
-import Text.Format
4  
-
5  
-formatString = "$p1 - ${p2} [$$$cost]"
6  
-
7  
-data Record = Record
8  
-  { p1    :: Int
9  
-  , p2    :: Int
10  
-  , cost  :: (Int, Int)
11  
-  }
12  
-
13  
-fields :: String -> Maybe (Record -> String)
14  
-fields "p1" = return $ show . p1
15  
-fields "p2" = return $ show . p2
16  
-fields "cost" = return $ (\(d, _) -> show d) . cost
17  
-fields _ = Nothing
18  
-
19  
-postponeMaybe :: (a -> Maybe (b -> c)) -> a -> b -> Maybe c
20  
-postponeMaybe f a b = do
21  
-                        f' <- f a
22  
-                        return $ f' b
23  
-
24  
-ff :: Record -> String -> Maybe String
25  
-ff = flip $ postponeMaybe fields
26  
-
27  
-sample = Record 3 56 (5, 44)
28  
-sampleString = "3 - 56 [$5]"
29  
-
30  
-scanMain = scanFormatString formatString sampleString
31  
-
32  
-renderMain = renderFormatString formatString (ff sample)
33  
-
34  
-main = case scanMain of
35  
-        Left s -> putStrLn s
36  
-        Right s -> print s
37  
-

0 notes on commit b217920

Please sign in to comment.
Something went wrong with that request. Please try again.