Send Beginners mailing list submissions to beginners@haskell.org To subscribe or unsubscribe via the World Wide Web, visit http://www.haskell.org/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: question on types (Jake Penton) 2. Re: question on types (Brandon Allbery) 3. Re: question on types (Brent Yorgey) 4. Re: question on types (Jake Penton) 5. Re: question on types (Brandon Allbery) 6. Re: question on types (Daniel Fischer) 7. Building Haskell Platform with shared libraries? (Mister Globules) ---------------------------------------------------------------------- Message: 1 Date: Fri, 29 Jul 2011 11:02:26 -0400 From: Jake Penton <d...@arqux.com> Subject: Re: [Haskell-beginners] question on types To: Haskell Beginners <beginners@haskell.org> Message-ID: <f2285e18-14fd-48f4-a538-f7d04901a...@arqux.com> Content-Type: text/plain; charset=us-ascii On 2011-07-29, at 10:02 AM, Daniel Seidel wrote: > On Fri, 2011-07-29 at 09:49 -0400, Jake Penton wrote: >> For example, this does not compile: >> >> f :: Fractional a => a >> f = 3.14 > > I can load this to ghci and also compile > Yeah, sorry - so can I. I must have screwed up earlier. Fat fingers, bleary eyes.... But, getting back to my point (or possibly making an unrelated one for all I know), how about this, which I *hope* I am right in saying does NOT compile, even though Bool is an instance of Ord: g :: Ord a => a g = True It still seems to me that the mere presence of a constraint does not make a difference by itself. Does the difference here lie in compiler calls to fromFractional or fromIntegral in appropriate cases? - J - ------------------------------ Message: 2 Date: Fri, 29 Jul 2011 11:22:47 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] question on types To: Jake Penton <d...@arqux.com>, Haskell Beginners <Beginners@haskell.org> Message-ID: <CAKFCL4WFx=5eq1kkmfn49i2wbjtmdwtdqxvjvvpylcn7k6n...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Ask yourself this: is True *every* instance of Ord? You are expecting it to be an "any", but it's an "every" (forall). By the way, True happens to be an instance of Ord but it doesn't have to be. You're working backwards here, I think. It happens that useful operations on things in class Ord generally produce Bool; that doesn't mean Bool must be Ord. -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ------------------------------ Message: 3 Date: Fri, 29 Jul 2011 11:24:45 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] question on types To: beginners@haskell.org Message-ID: <20110729152445.ga9...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii On Fri, Jul 29, 2011 at 11:02:26AM -0400, Jake Penton wrote: > > On 2011-07-29, at 10:02 AM, Daniel Seidel wrote: > > > On Fri, 2011-07-29 at 09:49 -0400, Jake Penton wrote: > >> For example, this does not compile: > >> > >> f :: Fractional a => a > >> f = 3.14 > > > > I can load this to ghci and also compile > > > > Yeah, sorry - so can I. I must have screwed up earlier. Fat fingers, bleary > eyes.... > > But, getting back to my point (or possibly making an unrelated one for all I > know), how about this, which I *hope* I am right in saying does NOT compile, > even though Bool is an instance of Ord: > > g :: Ord a => a > g = True > > It still seems to me that the mere presence of a constraint does not > make a difference by itself. Does the difference here lie in > compiler calls to fromFractional or fromIntegral in appropriate > cases? Yes. The difference is that numeric literals are special -- they are polymorphic. 3 has type (Num a) => a, and 3.14 has type (Fractional a) => a. So, f :: Fractional a => a promises to be able to take on ANY fractional type, and sure enough, 3.14 can be any fractional type. However, g :: Ord a => a promises to be able to take on ANY Ord type, but True has type Bool, which is too specific. I should be able to write (for example) if g < 'x' then ... else ... using g at type Char (since Char is an instance of Ord), but you can easily see that this will not work if g = True. Hence the error. -Brent ------------------------------ Message: 4 Date: Fri, 29 Jul 2011 12:14:30 -0400 From: Jake Penton <d...@arqux.com> Subject: Re: [Haskell-beginners] question on types To: Brandon Allbery <allber...@gmail.com> Cc: Haskell Beginners <Beginners@haskell.org> Message-ID: <5c8d5cd1-7ee5-4763-a79d-00c101a9f...@arqux.com> Content-Type: text/plain; charset=us-ascii On 2011-07-29, at 11:22 AM, Brandon Allbery wrote: > Ask yourself this: is True *every* instance of Ord? You are expecting > it to be an "any", but it's an "every" (forall). > > By the way, True happens to be an instance of Ord but it doesn't have > to be. You're working backwards here, I think. It happens that > useful operations on things in class Ord generally produce Bool; that > doesn't mean Bool must be Ord. > Right - actually, I did not expect it to compile. I gave the code as, perhaps, a counterexample to what some other responses seemed to be asserting, although it is possible I did not get their point(s) correctly. They seemed to say that adding a constraint is of itself what makes the cases that used numeric literals work. But it seems (as described in Brent Yorgey's post) that there is more to it than that. - J - ------------------------------ Message: 5 Date: Fri, 29 Jul 2011 12:21:17 -0400 From: Brandon Allbery <allber...@gmail.com> Subject: Re: [Haskell-beginners] question on types To: Jake Penton <d...@arqux.com> Cc: Haskell Beginners <Beginners@haskell.org> Message-ID: <CAKFCL4WqJk3FMj1c=zM+RSDK3yww75EeOC_qRN=mmzgyebf...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 It's true but incomplete: the implicit fromIntegral is what enables the numeric example to produce any numeric type, whike the Num constraint just announces that fact. The constraint itself is a contract; fromIntegral is what delivers on the contract. On 2011-07-29, Jake Penton <d...@arqux.com> wrote: > > On 2011-07-29, at 11:22 AM, Brandon Allbery wrote: > >> Ask yourself this: is True *every* instance of Ord? You are expecting >> it to be an "any", but it's an "every" (forall). >> >> By the way, True happens to be an instance of Ord but it doesn't have >> to be. You're working backwards here, I think. It happens that >> useful operations on things in class Ord generally produce Bool; that >> doesn't mean Bool must be Ord. >> > > Right - actually, I did not expect it to compile. I gave the code as, > perhaps, a counterexample to what some other responses seemed to be > asserting, although it is possible I did not get their point(s) correctly. > They seemed to say that adding a constraint is of itself what makes the > cases that used numeric literals work. But it seems (as described in Brent > Yorgey's post) that there is more to it than that. > > - J - > > -- brandon s allbery allber...@gmail.com wandering unix systems administrator (available) (412) 475-9364 vm/sms ------------------------------ Message: 6 Date: Fri, 29 Jul 2011 18:50:25 +0200 From: Daniel Fischer <daniel.is.fisc...@googlemail.com> Subject: Re: [Haskell-beginners] question on types To: beginners@haskell.org Message-ID: <201107291850.25520.daniel.is.fisc...@googlemail.com> Content-Type: Text/Plain; charset="iso-8859-1" On Friday 29 July 2011, 18:14:30, Jake Penton wrote: > On 2011-07-29, at 11:22 AM, Brandon Allbery wrote: > > Ask yourself this: is True *every* instance of Ord? You are expecting > > it to be an "any", but it's an "every" (forall). > > > > By the way, True happens to be an instance of Ord but it doesn't have > > to be. You're working backwards here, I think. It happens that > > useful operations on things in class Ord generally produce Bool; that > > doesn't mean Bool must be Ord. > > Right - actually, I did not expect it to compile. I gave the code as, > perhaps, a counterexample to what some other responses seemed to be > asserting, although it is possible I did not get their point(s) > correctly. They seemed to say that adding a constraint is of itself > what makes the cases that used numeric literals work. Given the fact that per the report a numeric literal is interpreted as a call to fromInteger or fromRational (depending on whether it's an integer literal or a fractional literal), the addition of the constraint is all that is needed to make it work, since by those functions' types, the value represented by a numeric literal is polymorphic. f = 1 is really f = fromInteger 1& (where n& stands for the Integer of the appropriate value, it's not Haskell; in GHC [with integer-gmp], it would be f = fromInteger (S# 1#) where S# is a constructor of Integer [MagicHash extension required to use it] and 1# is a literal of type Int#, raw signed machine int, four or eight bytes of raw memory). True, on the other hand, is a monomorphic value of type Bool, it cannot have any other type than Bool and trying to specify any other type for it leads to a compile time error. > But it seems (as > described in Brent Yorgey's post) that there is more to it than that. The fundamental difference is monomorphic vs. polymorphic expressions. A monomorphic expression like [True] has a specific type, it doesn't make sense to add constraints to it (but it makes sense to ask whether constraints are satisfied for using it). A polymorphic expression like (toEnum 0) can have many types, but in general the types it can have are constrained by the types of subexpressions/used functions. There is a minimal set of constraints you need to specify, e.g. l = [toEnum 0, 3] needs the constraints (Enum a) and (Num a) in the type signature l :: (Num a, Enum a) => [a] but you can use more or more restrictive constraints to specify a less general type than it could have, for example l :: (Enum a, Bounded a, Num a, Read a) => [a] or l :: (Enum a, RealFrac a) => [a] are valid signatures since they are less general/more constrained than the first one. You could also give a monomorphic signature, l :: [Double], which will compile if and only if the specified type of list elements belongs to Num and Enum. ------------------------------ Message: 7 Date: Sat, 30 Jul 2011 06:02:00 +0000 (UTC) From: Mister Globules <globu...@gmail.com> Subject: [Haskell-beginners] Building Haskell Platform with shared libraries? To: beginners@haskell.org Message-ID: <loom.20110730t075117-...@post.gmane.org> Content-Type: text/plain; charset=us-ascii Hi, I'm installing the Haskell Platform (2011.2.0.1) from source on Kubuntu. If I follow the recommended steps (configure, make, make install) it doesn't build any shared libraries. I've tried a few hacks (e.g. export EXTRA_CONFIGURE_OPTS=--enable-shared), but they result in build errors. Currently, I do a "cabal --reinstall install" for each of the packages in the platform, but I was wondering if there's a more "official" way to do it when building the platform itself. - Globules ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 37, Issue 66 *****************************************