This might be a reasonable solution for the the "concatenation" operator
you want:
[This does not solve the numeric ambiguity - I think that is impossible.]

infixl 1 <<

class Stringable a where
  (<<) :: String -> a -> String

instance Stringable a => Stringable [a] where
  s << [] = s
  s << (x:xs) = s << x << xs

instance Stringable Int where
  s << x = s ++ show x
  
instance Stringable Char where
  s << x = s ++ [x]

main = print $ "Maybe " << (2+2::Int) << " is " << 'a' << " solution"

I hope you find << sufficiently keyboard friendly ;-)
(If you don't like having to put a string as the first argument you could
  define a constant

  cout :: String
  cout = ""

 and write

  cout << "Maybe " << (2+2::Int) << " is " << 'a' << " solution"
)

Worth noting is that many variants of this theme is possible using other
types than String to store the information:

(<<) :: Printable a => IO () -> a -> IO ()
(<<) :: Pretty a => Doc -> a -> Doc
...


Patrik Jansson



Reply via email to