[Haskell] please improve this code - thanks

Me itmitica at gmail.com
Sat Aug 24 14:45:29 CEST 2013


Hi all.
I'm new to haskell. I have a puny piece of code:

import Data.List.Split

padL :: Int -> String -> String
padL n s
     | length s < n = replicate (n - length s) '0' ++ s
     | otherwise = s

strInc :: String -> String -> String
strInc sep str =
         let strarr = splitOn sep str
             zprefix = strarr !! 0
             znumber = strarr !! 1
         in zprefix ++ sep ++ padL ( length (znumber) ) ( show ( read (  
znumber ) + 1 ) )

Prelude> :l strinc
[1 of 1] Compiling Main ( strinc.hs, interpreted )
Ok, modules loaded: Main.
*Main> strInc "-" "xs-00009"
"xs-00010"
*Main> strInc "<>" "yxs<>000099"
"yxs<>000100"

Is it good haskell, bad haskell or average haskell? How can it be  
rewritten?
Thanks.




More information about the Haskell mailing list