[Haskell-beginners] Re: multreplace

prad prad at towardsfreedom.com
Fri Jul 2 02:58:56 EDT 2010


On Thu, 1 Jul 2010 22:31:28 -0700
prad <prad at towardsfreedom.com> wrote:

> so back to
> the drawing board!
>
here's what emerged:

======
#!/usr/bin/env runghc

module Main where

import Useful as U

main = do

    let str = "This is original string"
    let ss  = ["orig","ing"]
    let rs  = ["very orig","ucture"]

    putStrLn $ head (multRepl str ss rs)
    
    
--multRepl :: String -> [String] -> [String] -> [String]
multRepl [] _ _             = []
multRepl str (s:ss) (r:rs)  = do
    let newStr = U.replace str s r
    if (length ss) == 0 
       then return newStr 
       else multRepl newStr ss rs 
=======

this does produce the correct output:
This is very original structure


and here are my questions:

1. the type
*Main Useful> :t multRepl 
multRepl :: (Eq t) => [t] -> [[t]] -> [[t]] -> [[t]]

but i have it returning newStr which equals U.replace str s r
and the type of U.replace is String as shown below
*Main Useful> :t Useful.replace
Useful.replace :: (Eq a) => [a] -> [a] -> [a] -> [a]

so why is it returning [String] when newStr isn't a list of strings?

2. is the way i've done it proper haskellian? it took me quite some
time to think this out trying to find my way through the fog of
imperative programming.

(my apologies for replying to my own posts - as well as my
appreciation for your assistance)

-- 
In friendship,
prad

                                      ... with you on your journey
Towards Freedom
http://www.towardsfreedom.com (website)
Information, Inspiration, Imagination - truly a site for soaring I's




More information about the Beginners mailing list