Skip to main content
added 32 characters in body
Source Link

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.

Bash w/ Haskell w/ C preprocessor, 195 198 275

echo '#define i(c)instance c String where
#define u unwords[a,b,
i(Num) fromInteger=show;a+b=u"+"];a-b=u"-"];a*b=u"*"]
i(Fractional) a/b=u"/"]
main=putStr$'$*|runghc -XFlexibleInstances -XCPP 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

Bash w/ Haskell w/ C preprocessor sed, 180 195 198 275

echo 'CNumO+O-O*fromInteger=show
CFractionalO/
main=putStr$'$*|sed 's/C\([^O]*\)/instance \1 String where /g
s/O\(.\?\)/a\1b=unwords\[a,b,\"\1\"];/g'|runghc -XFlexibleInstances 2>w

At last, it's not longer than the C solution anymore. The crucial Haskell part is almost as lazy as the bc solution...

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.

added 36 characters in body
Source Link

Bash w/Haskell Haskell w/ C preprocessor, 198195 198 275

echo 'u=unwords
'#define i(c)instance Numc String where
#define fromInteger=show;a+b=u[au unwords[a,b,"+"];a
i(Num) fromInteger=show;a+b=u"+"];a-b=u[a,b,"b=u"-"];a*b=u[a,b,"*"]"];a*b=u"*"]
instance i(Fractional String where) a/b=u[a,b,"b=u"/"]
main=putStr$'$*|runghc -XFlexibleInstances -XCPP 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

Bash w/Haskell, 198 275

echo 'u=unwords
instance Num String where fromInteger=show;a+b=u[a,b,"+"];a-b=u[a,b,"-"];a*b=u[a,b,"*"]
instance Fractional String where a/b=u[a,b,"/"]
main=putStr$'$*|runghc -XFlexibleInstances 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

Bash w/ Haskell w/ C preprocessor, 195 198 275

echo '#define i(c)instance c String where
#define u unwords[a,b,
i(Num) fromInteger=show;a+b=u"+"];a-b=u"-"];a*b=u"*"]
i(Fractional) a/b=u"/"]
main=putStr$'$*|runghc -XFlexibleInstances -XCPP 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

deleted 90 characters in body
Source Link

Bash w/Haskell, 275198 275

echo 'data E=N Integer|E:+E|E:-E|E:*E|E:/E'u=unwords
instance Num EString where fromInteger=N;a+b=a:+b;afromInteger=show;a+b=u[a,b,"+"];a-b=a:b=u[a,b,"-b;a*b=a:*b"];a*b=u[a,b,"*"]
instance Fractional EString where a/b=a:/b
d a o b=unwords[p ab=u[a,p b,o]
p(N n)=show n
p(a:+b)=d a"+"b"/"]
p(a:-b)=dmain=putStr$'$*|runghc a"-"b
p(a:*b)=d a"*"b
p(a:/b)=d a"/"b
main=putStr.p$'$*|runghcXFlexibleInstances 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

Bash w/Haskell, 275

echo 'data E=N Integer|E:+E|E:-E|E:*E|E:/E
instance Num E where fromInteger=N;a+b=a:+b;a-b=a:-b;a*b=a:*b
instance Fractional E where a/b=a:/b
d a o b=unwords[p a,p b,o]
p(N n)=show n
p(a:+b)=d a"+"b
p(a:-b)=d a"-"b
p(a:*b)=d a"*"b
p(a:/b)=d a"/"b
main=putStr.p$'$*|runghc 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

Bash w/Haskell, 198 275

echo 'u=unwords
instance Num String where fromInteger=show;a+b=u[a,b,"+"];a-b=u[a,b,"-"];a*b=u[a,b,"*"]
instance Fractional String where a/b=u[a,b,"/"]
main=putStr$'$*|runghc -XFlexibleInstances 2>w

Pity, it's longer than the C solution though I was almost as lazy as @Geoff with the bc one...

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.

Source Link
Loading