git.iko.soy/haskell-generate
on master help sign in
.travis.yml+5−3
since splitsnapshots
unifiedsplit
@@ -1,7 +1,9 @@
1env:
1env:
2 - GHCVER=7.4.2 CABALVER=1.16
2 - GHCVER=7.4.2 CABALVER=1.16
3 - GHCVER=7.6.3 CABALVER=1.18
3 - GHCVER=7.6.3 CABALVER=1.18
4+ - GHCVER=7.8.3 CABALVER=1.20
5+ - GHCVER=7.10.2 CABALVER=1.22
4− - GHCVER=head CABALVER=1.18
6+ - GHCVER=head CABALVER=1.22
5
7
6before_install:
8before_install:
7 - sudo add-apt-repository -y ppa:hvr/ghc
9 - sudo add-apt-repository -y ppa:hvr/ghc
@@ -20,5 +22,5 @@ script:
20
22
21matrix:
23matrix:
22 allow_failures:
24 allow_failures:
23− - env: GHCVER=head CABALVER=1.18
25+ - env: GHCVER=head CABALVER=1.22
24− fast_finish: true
26+ fast_finish: true
LICENSE+1−1
@@ -1,4 +1,4 @@
1−Copyright 2013 Benno Fünfstück
1+Copyright 2013-2015 Benno Fünfstück
2
2
3All rights reserved.
3All rights reserved.
4
4
README.md−1
@@ -102,4 +102,3 @@ declareFunction 'permutations -- This generates the same code as above, but is m
102## Contributing
102## Contributing
103
103
104If you have an idea, a question or a bug report, open an issue on github. You can also find me on freenode in the #haskell channel, my nick is bennofs.
104If you have an idea, a question or a bug report, open an issue on github. You can also find me on freenode in the #haskell channel, my nick is bennofs.
105−
haskell-generate.cabal+9−6
@@ -1,5 +1,5 @@
1name: haskell-generate
1name: haskell-generate
2−version: 0.2
2+version: 0.2.4
3license: BSD3
3license: BSD3
4category: Code Generation, Language
4category: Code Generation, Language
5cabal-version: >= 1.10
5cabal-version: >= 1.10
@@ -9,9 +9,13 @@ maintainer: Benno Fünfstück <benno.fuenfstueck@gmail.com>
9stability: experimental
9stability: experimental
10homepage: http://github.com/bennofs/haskell-generate/
10homepage: http://github.com/bennofs/haskell-generate/
11bug-reports: http://github.com/bennofs/haskell-generate/issues
11bug-reports: http://github.com/bennofs/haskell-generate/issues
12−copyright: Copyright (C) 2013 Benno Fünfstück
12+copyright: Copyright (C) 2013-2015 Benno Fünfstück
13−synopsis: haskell-generate
13+synopsis: Typesafe generation of haskell source code
14−description: haskell-generate
14+description:
15+ This library provides an interface to generate haskell source code, verifying at compile time
16+ that the resulting code typechecks.
17+ See <https://github.com/bennofs/haskell-generate haskell-generate> for an
18+ introduction explaining how to use the library.
15build-type: Custom
19build-type: Custom
16
20
17extra-source-files:
21extra-source-files:
@@ -41,6 +45,7 @@ library
41 Language.Haskell.Generate.Expression
45 Language.Haskell.Generate.Expression
42 Language.Haskell.Generate.TH
46 Language.Haskell.Generate.TH
43 Language.Haskell.Generate.PreludeDef
47 Language.Haskell.Generate.PreludeDef
48+ other-extensions: TemplateHaskell
44
49
45test-suite doctests
50test-suite doctests
46 type: exitcode-stdio-1.0
51 type: exitcode-stdio-1.0
@@ -52,6 +57,4 @@ test-suite doctests
52 , doctest >= 0.9.1
57 , doctest >= 0.9.1
53 , filepath
58 , filepath
54 ghc-options: -Wall -threaded
59 ghc-options: -Wall -threaded
55− if impl(ghc<7.6.1)
56− ghc-options: -Werror
57 hs-source-dirs: tests
60 hs-source-dirs: tests
src/Language/Haskell/Generate/Monad.hs+21
@@ -3,6 +3,7 @@
3{-# LANGUAGE ScopedTypeVariables #-}
3{-# LANGUAGE ScopedTypeVariables #-}
4{-# LANGUAGE UndecidableInstances #-}
4{-# LANGUAGE UndecidableInstances #-}
5{-# LANGUAGE FlexibleInstances #-}
5{-# LANGUAGE FlexibleInstances #-}
6+{-# LANGUAGE CPP #-}
6module Language.Haskell.Generate.Monad
7module Language.Haskell.Generate.Monad
7 ( Generate(..), ExpG
8 ( Generate(..), ExpG
8 , runGenerate, newName
9 , runGenerate, newName
@@ -35,6 +36,8 @@ import Language.Haskell.Exts.SrcLoc
35import Language.Haskell.Exts.Syntax
36import Language.Haskell.Exts.Syntax
36import Language.Haskell.Generate.Expression
37import Language.Haskell.Generate.Expression
37
38
39+import Prelude
40+
38--------------------------------------------------------------------------------
41--------------------------------------------------------------------------------
39-- Generate expressions
42-- Generate expressions
40
43
@@ -61,7 +64,13 @@ generateExp = prettyPrint . runExpression . fst . runGenerate
61caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
64caseE :: ExpG x -> [(Pat, ExpG t)] -> ExpG t
62caseE v alt = do
65caseE v alt = do
63 v' <- v
66 v' <- v
67+#if MIN_VERSION_haskell_src_exts(1,17,0)
68+ alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') Nothing) a) alt
69+#elif MIN_VERSION_haskell_src_exts(1,16,0)
70+ alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedRhs $ runExpression a') (BDecls [])) a) alt
71+#else
64 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
72 alt' <- mapM (\(p,a) -> fmap (\a' -> Alt noLoc p (UnGuardedAlt $ runExpression a') (BDecls [])) a) alt
73+#endif
65 return $ Expression $ Case (runExpression v') alt'
74 return $ Expression $ Case (runExpression v') alt'
66
75
67-- | Import a function from a module. This function is polymorphic in the type of the resulting expression,
76-- | Import a function from a module. This function is polymorphic in the type of the resulting expression,
@@ -205,19 +214,31 @@ instance GenExp (FunRef t) where
205
214
206-- | Generate a ExportSpec for a given function item.
215-- | Generate a ExportSpec for a given function item.
207exportFun :: FunRef t -> ExportSpec
216exportFun :: FunRef t -> ExportSpec
217+#if MIN_VERSION_haskell_src_exts(1,16,0) && !MIN_VERSION_haskell_src_exts(1,17,0)
218+exportFun (FunRef name) = EVar NoNamespace (UnQual name)
219+#else
208exportFun (FunRef name) = EVar (UnQual name)
220exportFun (FunRef name) = EVar (UnQual name)
221+#endif
209
222
210-- | Add a declaration to the module. Return a reference to it that can be used to either apply the function to some values or export it.
223-- | Add a declaration to the module. Return a reference to it that can be used to either apply the function to some values or export it.
211addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
224addDecl :: Name -> ExpG t -> ModuleM (FunRef t)
212addDecl name e = ModuleM $ do
225addDecl name e = ModuleM $ do
213 let (body, mods) = runGenerate e
226 let (body, mods) = runGenerate e
227+#if MIN_VERSION_haskell_src_exts(1,17,0)
228+ tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) Nothing]])
229+#else
214 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
230 tell (mods, [FunBind [Match noLoc name [] Nothing (UnGuardedRhs $ runExpression body) $ BDecls []]])
231+#endif
215 return $ FunRef name
232 return $ FunRef name
216
233
217-- | Extract the Module from a module generator.
234-- | Extract the Module from a module generator.
218runModuleM :: ModuleG -> String -> Module
235runModuleM :: ModuleG -> String -> Module
219runModuleM (ModuleM act) name =
236runModuleM (ModuleM act) name =
237+#if MIN_VERSION_haskell_src_exts(1,16,0)
238+ Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False False Nothing Nothing Nothing) $ S.toList imps) decls
239+#else
220 Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False Nothing Nothing Nothing) $ S.toList imps) decls
240 Module noLoc (ModuleName name) [] Nothing export (map (\md -> ImportDecl noLoc md True False Nothing Nothing Nothing) $ S.toList imps) decls
241+#endif
221 where (export, (imps, decls)) = runWriter act
242 where (export, (imps, decls)) = runWriter act
222
243
223-- | Generate the source code for a module.
244-- | Generate the source code for a module.
src/Language/Haskell/Generate/PreludeDef.hs+1
@@ -60,6 +60,7 @@ fmap concat $ mapM declareNamedSymbol
60 , ('(++), "append'")
60 , ('(++), "append'")
61 , ('(!!), "index'")
61 , ('(!!), "index'")
62 , ('(==), "equal'")
62 , ('(==), "equal'")
63+ , ('(/=), "notequal'")
63 ]
64 ]
64
65
65(<>.) :: ExpG (b -> c) -> ExpG (a -> b) -> ExpG (a -> c)
66(<>.) :: ExpG (b -> c) -> ExpG (a -> b) -> ExpG (a -> c)
tests/doctests.hsc+1−2
@@ -20,18 +20,17 @@ import Data.List
20import System.Directory
20import System.Directory
21import System.FilePath
21import System.FilePath
22import Test.DocTest
22import Test.DocTest
23+import Prelude
23
24
24##ifdef mingw32_HOST_ARCH
25##ifdef mingw32_HOST_ARCH
25##ifdef i386_HOST_ARCH
26##ifdef i386_HOST_ARCH
26##define USE_CP
27##define USE_CP
27−import Control.Applicative
28import Control.Exception
28import Control.Exception
29import Foreign.C.Types
29import Foreign.C.Types
30foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
30foreign import stdcall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
31foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
31foreign import stdcall "windows.h GetConsoleCP" c_GetConsoleCP :: IO CUInt
32##elif defined(x86_64_HOST_ARCH)
32##elif defined(x86_64_HOST_ARCH)
33##define USE_CP
33##define USE_CP
34−import Control.Applicative
35import Control.Exception
34import Control.Exception
36import Foreign.C.Types
35import Foreign.C.Types
37foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool
36foreign import ccall "windows.h SetConsoleCP" c_SetConsoleCP :: CUInt -> IO Bool