Bash w/ Haskell w/ C preprocessorC preprocessor sed, 195180 195 198 275
echo '#define'CNumO+O-O*fromInteger=show
CFractionalO/
main=putStr$'$*|sed i's/C\(c[^O]*\)/instance c\1 String where
#define u unwords[a,b,
i(Num) fromInteger=show;a+b=u"+"];a-b=u"-"];a*b=u"*"]/g
is/O\(Fractional.\?\) a/b=u"a\1b=unwords\[a,b,\"\1\"];/"]
main=putStr$'$*|runghcg'|runghc -XFlexibleInstances -XCPP 2>w
PityAt last, it's not longer than the C solution though I wasanymore. The crucial Haskell part is almost as lazy as @Geoff with the bc onesolution...
Takes input as command-line parameters. A file w
with some ghc warning messages will be created, if you don't like this change to runghc 2>/dev/null
.