{"id":558,"date":"2014-11-11T06:45:03","date_gmt":"2014-11-11T04:45:03","guid":{"rendered":"http:\/\/www.glc.us.es\/~jalonso\/exercitium\/?p=558"},"modified":"2016-05-01T19:45:16","modified_gmt":"2016-05-01T17:45:16","slug":"precio-total","status":"publish","type":"post","link":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/precio-total\/","title":{"rendered":"Precio total"},"content":{"rendered":"<h4>Enunciado<\/h4>\n<pre lang=\"text\">\n-- Una funci\u00f3n de precio determina el precio de cada elemento; por\n-- ejemplo,\n--    precioCI :: String -> Int\n--    precioCI \"leche\"       = 10\n--    precioCI \"mantequilla\" = 18\n--    precioCI \"patatas\"     = 22\n--    precioCI \"chocolate\"   = 16\n-- \n-- Definir la funci\u00f3n\n--    precioTotal :: (String -> Int) -> [String] -> Int\n-- tal que (precioTotal f xs) es el precio total de los elementos de xs\n-- respecto de la funci\u00f3n de precio f. Por ejemplo,\n--    precioTotal precioCI [\"leche\", \"leche\", \"mantequilla\"]  ==  38\n--    precioTotal precioCI [\"chocolate\", \"mantequilla\"]       ==  34\n<\/pre>\n<h4>Soluciones<\/h4>\n<pre lang=\"haskell\">\n-- 1\u00aa soluci\u00f3n (por comprensi\u00f3n):\nprecioTotal1 :: (String -> Int) -> [String] -> Int\nprecioTotal1 f xs = sum [precioCI x | x <- xs]\n\n-- 2\u00aa soluci\u00f3n (por recursi\u00f3n):\nprecioTotal2 :: (String -> Int) -> [String] -> Int\nprecioTotal2 f []     = 0\nprecioTotal2 f (x:xs) = f x + precioTotal2 f xs\n\n-- 3\u00aa soluci\u00f3n (por plegado)\nprecioTotal3 :: (String -> Int) -> [String] -> Int\nprecioTotal3 f = foldr g 0\n    where g x y = f x + y\n\n-- 4\u00aa soluci\u00f3n (por plegado y lambda)\nprecioTotal4 :: (String -> Int) -> [String] -> Int\nprecioTotal4 f = foldr (\\x y -> f x + y) 0\n\n-- 5\u00aa soluci\u00f3n (por plegado y composici\u00f3n)\nprecioTotal5 :: (String -> Int) -> [String] -> Int\nprecioTotal5 f = foldr ((+) . f) 0\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Enunciado &#8212; Una funci\u00f3n de precio determina el precio de cada elemento; por &#8212; ejemplo, &#8212; precioCI :: String -> Int &#8212; precioCI \u00ableche\u00bb = 10 &#8212; precioCI \u00abmantequilla\u00bb = 18 &#8212; precioCI \u00abpatatas\u00bb = 22 &#8212; precioCI \u00abchocolate\u00bb = 16 &#8212; &#8212; Definir la funci\u00f3n &#8212; precioTotal :: (String -> Int) -> [String] ->&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_kad_post_transparent":"","_kad_post_title":"","_kad_post_layout":"","_kad_post_sidebar_id":"","_kad_post_content_style":"","_kad_post_vertical_padding":"","_kad_post_feature":"","_kad_post_feature_position":"","_kad_post_header":false,"_kad_post_footer":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"footnotes":"","_jetpack_memberships_contains_paid_content":false},"categories":[5],"tags":[35,8,94,11,90,6,40],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/558"}],"collection":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/comments?post=558"}],"version-history":[{"count":7,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/558\/revisions"}],"predecessor-version":[{"id":742,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/posts\/558\/revisions\/742"}],"wp:attachment":[{"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/media?parent=558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/categories?post=558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.glc.us.es\/~jalonso\/exercitium\/wp-json\/wp\/v2\/tags?post=558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}