[<<][meta][>>][..]
Sat Jul 23 23:13:42 CEST 2011

Textual representation: no intermediate data type

I guess this is a similar question than: can we have a writer monad
implementation?

Anyways, the string concatenation code is really straightforward:

data Print a = Print String
               deriving (Show, Eq)
                        
prt x = Print $ show x
prt1 op (Print x)           = Print $ concat [op,"(",x,")"]
prt2 op (Print x) (Print y) = Print $ concat [op,"(",x,",",y,")"]

instance Symantics Print where
  int = prt
  float = prt
  
  isign = prt1 "isign"
  iabs  = prt1 "iabs"
  iadd  = prt2 "iadd"
  imul  = prt2 "iadd"  
          
  fsign = prt1 "fsign"
  fabs  = prt1 "fabs"
  fadd  = prt2 "fadd"
  fmul  = prt2 "fadd"  

  i2f   = prt1 "i2f"                        
  f2i   = prt1 "f2i"


This essentially ignores the type parameter, so it seems that the same
technique can be used for terms.



[Reply][About]
[<<][meta][>>][..]