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    ) whereimport           Data.List  (intersperse)import           Data.Maybe (fromMaybe)import           Data.Text  ()import           Data.Text  (pack, strip, unpack)import           Text.Regex (mkRegex, splitRegex)(//) :: Maybe a -> a -> a(//) = flip fromMaybestripString = (unpack . strip . pack)toRVec :: String -> Maybe String -> Maybe Bool ->  StringtoRVec orig delim' toStrip' =  let      delim = delim' // [ \n]+      toStrip = toStrip' // True      ws = splitRegex (mkRegex delim) $ stripString orig      ws1 = map (\w -> \ ++ w ++ \) $ if toStrip then                                                      map stripString ws                                                    else                                                      ws      ws2 = intersperse , ws1      res = foldl (++)  ws2   in c( ++ res ++ )Any suggestion for improvements are welcome. 
Convert a string into an R vector expression
haskell;regex
How I would do it:import Data.List.Splitimport Data.Listfoo delim s = c(\ ++ intercalate \,\ (wordsBy (`elem` delim) s) ++ \)reads yoursNo 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.