<div dir="ltr"><div>It is because the type of your function all does not match its definition.  The type should be</div><div><br></div><div>all :: (a -> Bool) -> [a] -> Bool</div><div><br></div><div>You can read it like this, take a function from a to bool, a list of a's and then give back a bool.</div><div>Alternatively you can read it like this.  Take a function from a to bool and return a function that takes a list of a's and returns a bool.</div><div><br></div><div>In your original type, the list was restricted to boolean only, but the function can take any a, and so they don't match, which you can see in the error message.<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Aug 15, 2018 at 1:08 PM, trent shipley <span dir="ltr"><<a href="mailto:trent.shipley@gmail.com" target="_blank">trent.shipley@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I am trying to solve Hutton 2016 exercise 7.2a.  My attempt gets the same error message as the one below.  The problem with the error message below is that it is for the book's solved example, so I have no idea how to make it work.  I suspect I have GHCi configured wrong, or an old version that is buggy on Mac, or such.</div><div><br></div><div>Help is appreciated.</div><div><br></div><div>Also, at this point I am having trouble reading these function declarations.</div><div><br></div><div><div>all :: (a -> Bool) -> [Bool] -> Bool</div><div>all b ls = and (map b ls)</div><div><br></div><div>My try:</div><br class="m_2773854824657784354inbox-inbox-Apple-interchange-newline"></div><div><div>all :: -- name of function defined</div><div>(a ->  -- maps to "all"</div><div>Bool -- maps to boolean function b</div><div>) -> [Bool] -- maps to input ls </div><div>-> Bool -- maps to return type of "all"</div><div>all b ls = and (map b ls)</div><div><br></div><div>OR (right?)</div><div><br></div><div><div>all :: -- name of function defined</div><div>(a ->  Bool)  function of type a returns bool</div><div>-> [Bool] -- maps to input ls </div><div>-> Bool -- maps to return type of "all"</div><div>all b ls = and (map b ls)</div><br class="m_2773854824657784354inbox-inbox-Apple-interchange-newline"></div><div>------</div><div><br></div><div>Book example</div><div><br></div><div><div>all :: (a -- maps to "all"</div><div>-> Bool -- input function type</div><div>) -> [Bool] -- implied list of things mapped over</div><div>-> Bool -- returned</div><div>all p = and . map p</div><div><br></div><div>OR (right?)</div><br class="m_2773854824657784354inbox-inbox-Apple-interchange-newline"></div><div>all :: -- name of defined function</div><div>(a -> Bool) -- input function of type a returns type Bool</div><div> -> [Bool] -- implied list to work on</div><div>-> Bool -- return type</div><div>all p = and . map p</div><div><br></div><br class="m_2773854824657784354inbox-inbox-Apple-interchange-newline"></div><div><br></div><div>============================</div><div><br></div><div>-- CODE</div><div><br></div><div>{--</div><div>2. Without looking at the definitions from the standard prelude, define the following higher-order library functions on lists. </div><div><br></div><div>a.Decide if all elements of a list satisfy a predicate: </div><div>all :: (a -> Bool) -> [Bool] -> Bool </div><div><br></div><div>b.Decide if any element of a list satisfies a predicate: </div><div>any :: (a -> Bool) -> [Bool] -> Bool </div><div><br></div><div>c.Select elements from a list while they satisfy a predicate: </div><div>takeWhile :: (a -> Bool) -> [a] -> [a] </div><div><br></div><div>d.Remove elements from a list while they satisfy a predicate: dropWhile :: (a -> Bool) -> [a] -> [a] </div><div><br></div><div>Note: in the prelude the first two of these functions are generic functions rather than being specific to the type of lists.</div><div><br></div><div>Hutton, Graham. Programming in Haskell (Kindle Locations 2806-2819). Cambridge University Press. Kindle Edition. </div><div>--}</div><div><br></div><div>import Prelude hiding (all)</div><div><br></div><div>{-- My attempt. Presumably bad.</div><div> -- I swear GHCi was happy with it yesterday.</div><div><br></div><div>all :: (a -> Bool) -> [Bool] -> Bool</div><div>all b ls = and (map b ls)</div><div><br></div><div>--}</div><div><br></div><div>-- from book</div><div><br></div><div>all :: (a -> Bool) -> [Bool] -> Bool</div><div>all p = and . map p</div><div><br></div><div>{--</div><div><br></div><div>>From GHCi on Mac</div><div><br></div><div>Prelude> :r</div><div>[1 of 1] Compiling Main             ( ex7_2a.hs, interpreted )</div><div><br></div><div>ex7_2a.hs:30:9: error:</div><div>    • Couldn't match type ‘a’ with ‘Bool’</div><div>      ‘a’ is a rigid type variable bound by</div><div>        the type signature for:</div><div>          all :: forall a. (a -> Bool) -> [Bool] -> Bool</div><div>        at ex7_2a.hs:29:1-36</div><div>      Expected type: [Bool] -> Bool</div><div>        Actual type: [a] -> Bool</div><div>    • In the expression: and . map p</div><div>      In an equation for ‘all’: all p = and . map p</div><div>    • Relevant bindings include</div><div>        p :: a -> Bool (bound at ex7_2a.hs:30:5)</div><div>        all :: (a -> Bool) -> [Bool] -> Bool (bound at ex7_2a.hs:30:1)</div><div>   |</div><div>30 | all p = and . map p</div><div>   |         ^^^^^^^^^^^</div><div>Failed, no modules loaded.</div><div><br></div><div>--}</div></div>
<br>______________________________<wbr>_________________<br>
Beginners mailing list<br>
<a href="mailto:Beginners@haskell.org">Beginners@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/beginners</a><br>
<br></blockquote></div><br></div>