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. Re: Why do i need to specify the class of a here at all? (Patrik Iselind) 2. Fwd: Re: Multiple letters between -> -> (Marcus Manning) ---------------------------------------------------------------------- Message: 1 Date: Fri, 24 Nov 2017 22:32:17 +0100 From: Patrik Iselind <patrik....@gmail.com> To: beginners@haskell.org Subject: Re: [Haskell-beginners] Why do i need to specify the class of a here at all? Message-ID: <0b94896c-7d1f-bd65-2177-3b0f2d54a...@gmail.com> Content-Type: text/plain; charset="utf-8"; Format="flowed" Den 2017-11-24 kl. 20:04, skrev Quentin Liu: > >> Yes, you could pass the function a list of strings as well. A >> string is just a list of Chars. The type signature `a` does not >> restrict the range of types you could pass to the function. >> >> That seem strange to me. Wouldn't that mean that i could write the >> declaration of myOrderFunc as `myOrderFunc :: a -> a -> Ordering` as >> well? GHCI give me an error on this though so obviously it's wrong. I >> just don't see why. Why cannot a represent [b]? > > Could you copy and paste the error message here? Sure, the error i get follows ``` exercises.hs:33:13: Couldn't match expected type ‘[b0]’ with actual type ‘a’ ‘a’ is a rigid type variable bound by the type signature for myOrderFunc :: a -> a -> Ordering at exercises.hs:31:16 Relevant bindings include y :: a (bound at exercises.hs:32:15) x :: a (bound at exercises.hs:32:13) myOrderFunc :: a -> a -> Ordering (bound at exercises.hs:32:1) In the first argument of ‘myLen’, namely ‘x’ In the first argument of ‘(<)’, namely ‘myLen x’ Failed, modules loaded: none. ``` Attaching the updated exercises.hs for reference. I'm still not very good at interpreting Haskell's error messages, they are quite cryptic to me. My interpretation/guess of the above is that my `a` is too 'wide' or how you express it. Haskell seem to expect some form of list. Most likely since i want a length and lists are perhaps everything in Haskell that can produce a length. I've hardly scratched the surface of what i imagine is Haskell so i cannot say anything for sure yet. > > The way I use to think about type signature is, when you trying to > substitute type variables such as `a`, substitute it into a concrete > type that you are working with. I'm having a hard time understanding your way of thinking about type signatures. Could you perhaps elaborate a bit more on it? // Patrik -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171124/992ceca1/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: exercises.hs Type: text/x-haskell Size: 987 bytes Desc: not available URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171124/992ceca1/attachment-0001.hs> ------------------------------ Message: 2 Date: Sat, 25 Nov 2017 13:06:03 +0100 From: Marcus Manning <icons...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] Fwd: Re: Multiple letters between -> -> Message-ID: <ef75b987-dee3-ff03-2e1f-f1a28d833...@gmail.com> Content-Type: text/plain; charset="utf-8"; Format="flowed" -------- Forwarded Message -------- Subject: Re: [Haskell-beginners] Multiple letters between -> -> Date: Sat, 25 Nov 2017 13:05:25 +0100 From: Marcus Manning <icons...@gmail.com> To: Francesco Ariis <fa...@ariis.it> Sorry, for the long break. Thanks for replying. I do not believe that h is a higher kinded type. What I want to express is that a function f could take a type constructor as argument and simply returns it, but f Maybe throws an Error <interactive>:13:3: error: • Data constructor not in scope: Maybe :: h a • Perhaps you meant variable ‘maybe’ (imported from Prelude) So what instead does h a mean in a function declaration? Cheers, Marcus. On 11/23/2017 06:27 PM, Francesco Ariis wrote: > On Thu, Nov 23, 2017 at 06:19:51PM +0100, Marcus Manning wrote: >> Hi, >> >> Original I thought a Signature like: >> >> f :: h a -> h a >> >> means that h is a higher kinded type just like in Type Classes ( for >> instance f in Functor f). >> >> But I heard such a meaning is not allowed in normal Haskell functions. What >> instead is the meaning of h a? > Hello Marcus, > you can write that but, since we know nothing about `h` and `a`, > the only possible (non-undefined) function to implement that > signature is: > > f :: h a -> h a > f = id > > Any other implementation would require us to know something about h, > hence a typeclass-constraint (e.g. Functor h =>) on h. > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.haskell.org/pipermail/beginners/attachments/20171125/e42f9f2c/attachment-0001.html> ------------------------------ Subject: Digest Footer _______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ End of Beginners Digest, Vol 113, Issue 24 ******************************************