Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners or, via email, send a message with subject or body 'help' to beginners-requ...@haskell.org
You can reach the person managing the list at beginners-ow...@haskell.org When replying, please edit your Subject line so it is more specific than "Re: Contents of Beginners digest..." Today's Topics: 1. Applying a function to two lists (Matt Williams) 2. Re: Applying a function to two lists (Francesco Ariis) 3. i have questions about Haskell (Eunsu Kim) ---------------------------------------------------------------------- Message: 1 Date: Fri, 22 Apr 2016 22:20:19 +0100 From: Matt Williams <matt.williams45...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Applying a function to two lists Message-ID: <571a9593.1040...@gmail.com> Content-Type: text/plain; charset=utf-8; format=flowed Dear List, I am stuck. I have a function that needs to apply each item of one list to every element of the second list in turn. So far, I have this function: checkNum :: Int -> [Int] -> (Int,[Int]) checkNum a b = (a,filter (check a) $ b) which implements what I need, but I now need to apply it to every element of the first list. I am looking for something like: list1 = [1,2,3,4,5,6] list2 = [1,2,3,4,5,6] map checkNum list1 list2 to return: [(1,[1]),(2[3,4,5]),(6,[3]) (I have tried to simplify this a little, so my apologies if it looks pointless - the real function is useful) Any help would be appreciated. Matt ------------------------------ Message: 2 Date: Fri, 22 Apr 2016 23:26:40 +0200 From: Francesco Ariis <fa...@ariis.it> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Applying a function to two lists Message-ID: <20160422212640.ga24...@casa.casa> Content-Type: text/plain; charset=us-ascii On Fri, Apr 22, 2016 at 10:20:19PM +0100, Matt Williams wrote: > I am looking for something like: > > list1 = [1,2,3,4,5,6] > list2 = [1,2,3,4,5,6] > > map checkNum list1 list2 > > to return: > > [(1,[1]),(2[3,4,5]),(6,[3]) > > (I have tried to simplify this a little, so my apologies if it looks > pointless - the real function is useful) > > Any help would be appreciated. > > Matt Hey Matt, if what you want is [checkNum 1 list2, checkNum 2 list2, etc.] then map (flip checknum list2) list1 is what you want (flip signature being :: (a -> b -> c) -> b -> a -> c) ------------------------------ Message: 3 Date: Fri, 22 Apr 2016 19:18:52 -0500 From: Eunsu Kim <wntuw...@gmail.com> To: beginners@haskell.org Subject: [Haskell-beginners] i have questions about Haskell Message-ID: <aed57dfb-6129-44ff-8509-28b79ef78...@gmail.com> Content-Type: text/plain; charset="utf-8" Hi when outputting the polynomial value, actually write out the polynomial, but: - skipping any missing monomials - not including any extraneous signs -not showing the constant term for the above example, the final line would be: The value of 1.0 x^3 - 2.0 x^2 + 10.0 evaluated at -1.0 is 7.0 how can I do this??? i have no idea now?. here is my code: evalpoly = do putStr "What is the degree of polynomial: " degree <- getLine coeffs <- (funcOfCoeff ((read degree::Int)+1) [] ) putStr "What value do you want to evaluate at: " value <- getLine putStr "The value of the polynomial is: " putStrLn (show (getResult (coeffs) (read value :: Float) )) --function loop to get coefficient-- funcOfCoeff 0 coeffs = do --to check the degree of 0 return coeffs --return list of coefficient funcOfCoeff degree coeffs = do putStr ("What is the x^" ++ show(degree-1)) putStr " coefficient: " coeff <- getLine loop <- funcOfCoeff (degree-1) ((read coeff :: Float) : coeffs) return loop getResult (coeffs) x = sum(map(\(a,b) -> a*x^b).zip coeffs.iterate (+1)$0) this is my output so far: > evalpoly What is the degree of the polynomial: 3 What is the x^3 coefficient: 1.0 What is the x^2 coefficient: - 2.0 What is the x^1 coefficient: 0 What is the x^0 coefficient: 10.0 What value do you want to evaluate at: -1.0 The value of the polynomial is 7.0 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160422/3b8d20f9/attachment.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 94, Issue 22 *****************************************