Convert a string into an R vector expression Problem: Given a arbitrary string, split by a given regex and format into an R vector expression. E.g. Convert "a..,b..,c,d" into 'c("a","b","c","d")', when the given regex is "[.,]+". 

Solution in haskell:

module Lib
    ( toRVec
    ) where


import           Data.List  (intersperse)
import           Data.Maybe (fromMaybe)
import           Data.Text  ()
import           Data.Text  (pack, strip, unpack)
import           Text.Regex (mkRegex, splitRegex)


(//) :: Maybe a -&gt; a -&gt; a
(//) = flip fromMaybe

stripString = (unpack . strip . pack)

toRVec :: String -&gt; Maybe String -&gt; Maybe Bool -&gt;  String
toRVec orig delim' toStrip' =
  let
      delim = delim' // "[ \n]+"
      toStrip = toStrip' // True
      ws = splitRegex (mkRegex delim) $ stripString orig
      ws1 = map (\w -&gt; "\"" ++ w ++ "\"") $ if toStrip then
                                                      map stripString ws
                                                    else
                                                      ws
      ws2 = intersperse "," ws1
      res = foldl (++) "" ws2
   in "c(" ++ res ++ ")"


Any suggestion for improvements are welcome.
How I would do it:

import Data.List.Split
import Data.List
foo delim s = "c(\"" ++ intercalate "\",\"" (wordsBy (`elem` delim) s) ++ "\")"


reads yours

No brackets needed around unpack . strip . pack.

I would replace if toStrip then map stripString ws else ws with (if toStrip then map stripString else id) ws.

Some of your names are unneeded; I would inline ws, ws1 and ws2 into where they are used (once ws is only used once), perhaps even res.

Instead of foldl (++), use concat.