mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-04-23 03:32:51 -06:00
transfer exx
This commit is contained in:
@@ -4,15 +4,15 @@ gf:
|
|||||||
echo "pm | wf math.gfcm" | gf MathEng.gf MathFre.gf
|
echo "pm | wf math.gfcm" | gf MathEng.gf MathFre.gf
|
||||||
|
|
||||||
hs: gf
|
hs: gf
|
||||||
echo "pg -printer=haskell | wf haskell/GSyntax.hs" | gf math.gfcm
|
echo "pg -printer=haskell | wf GSyntax.hs" | gf math.gfcm
|
||||||
|
|
||||||
run: hs
|
run: hs
|
||||||
ghc --make -o ./math -ihaskell haskell/Run.hs
|
ghc --make -o ./math TransferLoop.hs
|
||||||
strip math
|
strip math
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.gfc *.gfr haskell/*.o haskell/*.hi
|
rm -f *.gfc *.gfr *.o *.hi
|
||||||
|
|
||||||
distclean:
|
distclean:
|
||||||
rm -f GSyntax.hs math math.gfcm *.gfc *.gfr haskell/*.o haskell/*.hi
|
rm -f GSyntax.hs math math.gfcm *.gfc *.gfr *.o *.hi
|
||||||
|
|
||||||
|
|||||||
26
examples/tutorial/embedded/TransferDef.hs
Normal file
26
examples/tutorial/embedded/TransferDef.hs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
module TransferDef where
|
||||||
|
|
||||||
|
import GF.Embed.EmbedAPI (Tree)
|
||||||
|
import GSyntax
|
||||||
|
|
||||||
|
transfer :: Tree -> Tree
|
||||||
|
transfer = gf . answer . fg
|
||||||
|
|
||||||
|
answer :: GQuestion -> GAnswer
|
||||||
|
answer p = case p of
|
||||||
|
GOdd x -> test odd x
|
||||||
|
GEven x -> test even x
|
||||||
|
GPrime x -> test prime x
|
||||||
|
|
||||||
|
value :: GObject -> Int
|
||||||
|
value e = case e of
|
||||||
|
GNumber (GInt i) -> fromInteger i
|
||||||
|
|
||||||
|
test :: (Int -> Bool) -> GObject -> GAnswer
|
||||||
|
test f x = if f (value x) then GYes else GNo
|
||||||
|
|
||||||
|
prime :: Int -> Bool
|
||||||
|
prime x = elem x primes where
|
||||||
|
primes = sieve [2 .. x]
|
||||||
|
sieve (p:xs) = p : sieve [ n | n <- xs, n `mod` p > 0 ]
|
||||||
|
sieve [] = []
|
||||||
@@ -1,12 +1,12 @@
|
|||||||
module Main where
|
module Main where
|
||||||
|
|
||||||
import GF.Embed.EmbedAPI
|
import GF.Embed.EmbedAPI
|
||||||
import GSyntax
|
import TransferDef (transfer)
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = do
|
||||||
gr <- file2grammar "math.gfcm"
|
gr <- file2grammar "math.gfcm"
|
||||||
loop (translate answerTree gr)
|
loop (translate transfer gr)
|
||||||
|
|
||||||
loop :: (String -> String) -> IO ()
|
loop :: (String -> String) -> IO ()
|
||||||
loop trans = do
|
loop trans = do
|
||||||
@@ -21,21 +21,3 @@ translate tr gr = unlines . map transLine . lines where
|
|||||||
(lg,t:_):_ -> linearize gr lg (tr t)
|
(lg,t:_):_ -> linearize gr lg (tr t)
|
||||||
_ -> "NO PARSE"
|
_ -> "NO PARSE"
|
||||||
|
|
||||||
answerTree :: Tree -> Tree
|
|
||||||
answerTree = gf . answer . fg
|
|
||||||
|
|
||||||
answer :: GQuestion -> GAnswer
|
|
||||||
answer p = case p of
|
|
||||||
GOdd x -> test odd x
|
|
||||||
GEven x -> test even x
|
|
||||||
GPrime x -> test prime x
|
|
||||||
|
|
||||||
value :: GObject -> Int
|
|
||||||
value e = case e of
|
|
||||||
GNumber (GInt i) -> fromInteger i
|
|
||||||
|
|
||||||
test :: (Int -> Bool) -> GObject -> GAnswer
|
|
||||||
test f x = if f (value x) then GYes else GNo
|
|
||||||
|
|
||||||
prime :: Int -> Bool
|
|
||||||
prime = (< 8) ----
|
|
||||||
|
|||||||
Reference in New Issue
Block a user