language-haskell-extract

Module to automatically extract functions from the local code.

http://github.com/finnsson/template-helper

Version on this page:0.2.4
LTS Haskell 16.31:0.2.4@rev:1
Stackage Nightly 2020-06-16:0.2.4@rev:1
Latest on Hackage:0.2.4@rev:1

See all snapshots language-haskell-extract appears in

BSD-3-Clause licensed by Oscar Finnsson & Emil Nordling
Maintained by Oscar Finnsson
This version can be pinned in stack with:language-haskell-extract-0.2.4@sha256:339c6e5db9de6be1b202acdafbd636eb72e4e77837e18dff7455717fd87f69a9,1751

Module documentation for 0.2.4

language-haskell-extract contains some useful helper functions on top of Template Haskell.

functionExtractor extracts all functions after a regexp-pattern.

foo = "test"
boo = "testing"
bar = $(functionExtractor "oo$")

will automagically extract the functions ending with oo such as

bar = [("foo",foo), ("boo",boo)]

This can be useful if you wish to extract all functions beginning with test (for a test-framework) or all functions beginning with wc (for a web service).

functionExtractorMap works like functionsExtractor but applies a function over all function-pairs.

This functions is useful if the common return type of the functions is a type class.

Example:

secondTypeclassTest =
  do let expected = ["45", "88.8", "\"hej\""]
         actual = $(functionExtractorMap "^tc" [|\n f -> show f|] )
     expected @=? actual

tcInt :: Integer
tcInt = 45

tcDouble :: Double
tcDouble = 88.8

tcString :: String
tcString = "hej"