LINUX.ORG.RU

История изменений

Исправление Siborgium, (текущая версия) :

С Hope не знаком, но, полагаю, переписать не составит труда.

insStr :: [Char] -> Int -> [Char] -> [Char]
insStr d n f = a ++ f ++ b
  where n' = if n <= 1 then 0 else n - 1
        (a, b) = splitAt n' d
$ cat ins.hs 
insStr :: [Char] -> Int -> [Char] -> [Char]
insStr d n f = a ++ f ++ b
  where n' = if n <= 1 then 0 else n - 1
        (a, b) = splitAt n' d

main = do
  putStrLn $ show $ insStr "ABC" 2 "DEF"
  putStrLn $ show $ insStr "ABC" 10 "DEF"
$ runhaskell ins.hs
"ADEFBC"
"ABCDEF"

Исправление Siborgium, :

С Hope не знаком, но, полагаю, переписать не составит труда.

insStr :: [Char] -> Int -> [Char] -> [Char]
insStr d n f = a ++ f ++ b
  where n' = if n <= 1 then 0 else n - 1
        (a, b) = splitAt n' d
$ cat ins.hs 
insStr :: [Char] -> Int -> [Char] -> [Char]
insStr d n f = a ++ f ++ b
  where n' = if n <= 1 then 0 else n - 1
        (a, b) = splitAt n' d

main = do
  putStrLn $ show $ insStr "ABC" 2 "DEF"
  putStrLn $ show $ insStr "ABC" 10 "DEF"
$ runhaskell ins.hs
"ADEFBC"
"ABCDEF"

Исходная версия Siborgium, :

С Hope не знаком.

insStr :: [Char] -> Int -> [Char] -> [Char]
insStr d n f = a ++ f ++ b
  where n' = if n <= 1 then 0 else n - 1
        (a, b) = splitAt n' d
$ cat ins.hs 
insStr :: [Char] -> Int -> [Char] -> [Char]
insStr d n f = a ++ f ++ b
  where n' = if n <= 1 then 0 else n - 1
        (a, b) = splitAt n' d

main = do
  putStrLn $ show $ insStr "ABC" 2 "DEF"
  putStrLn $ show $ insStr "ABC" 10 "DEF"
$ runhaskell ins.hs
"ADEFBC"
"ABCDEF"