From 8e4e8da105547abec4fe27e837d13bf45d78e31b Mon Sep 17 00:00:00 2001 From: hallgren Date: Mon, 9 Feb 2015 16:24:33 +0000 Subject: Translating linearization functions to Haskell: support for variants MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By adding the flag -haskell=variants to the command line, GF will now generate linearization functions in Haskell that support variants. Variants are represented as lists in Haskell. Variants inside pre { ... } expressions are still ignored. TODO: apply some monad laws to generate more compact code (using an intermediate representation of the generated Haskell code, instead of pretty printing directly from the GF code). --- src/runtime/haskell/PGF/Haskell.hs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/runtime') diff --git a/src/runtime/haskell/PGF/Haskell.hs b/src/runtime/haskell/PGF/Haskell.hs index e09f6635e..d77395518 100644 --- a/src/runtime/haskell/PGF/Haskell.hs +++ b/src/runtime/haskell/PGF/Haskell.hs @@ -2,7 +2,7 @@ -- with @gf -output-format=haskell -haskell=concrete@ {-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-} module PGF.Haskell where -import Control.Applicative((<$>)) +import Control.Applicative((<$>),(<*>)) import Data.Char(toUpper) import Data.List(isPrefixOf) import qualified Data.Map as M @@ -54,9 +54,15 @@ class Has_s r a | r -> a where proj_s :: r -> a -- | Haskell representation of the GF record type @{s:t}@ data R_s t = R_s t deriving (Eq,Ord,Show) -instance (EnumAll t) => EnumAll (R_s t) where - enumAll = (R_s <$> enumAll) +instance (EnumAll t) => EnumAll (R_s t) where enumAll = R_s <$> enumAll instance Has_s (R_s t) t where proj_s (R_s t) = t -- | Coerce from any record type @{...,s:t,...}@ field to the supertype @{s:t}@ to_R_s r = R_s (proj_s r) + + +-- *** Variants + +infixr 5 +++ + +xs +++ ys = (++) <$> xs <*> ys \ No newline at end of file -- cgit v1.2.3