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: Change in type that I don't understand (David McBride) 2. Re: Change in type that I don't understand (Daniel Trstenjak) 3. Re: Change in type that I don't understand (David McBride) 4. Re: Change in type that I don't understand (David McBride) 5. Re: Change in type that I don't understand (Daniel Trstenjak) 6. applicative instance (sasa bogicevic) 7. Re: applicative instance (Benjamin Edwards) ---------------------------------------------------------------------- Message: 1 Date: Fri, 27 Jan 2017 08:35:08 -0500 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Change in type that I don't understand Message-ID: <can+tr42qgsgmdos5g7arvfayn+m8shthx4mff31-pehj9nl...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 If you have the Monomorphism restriction set, it will choose types based on the type defaulting rules (Num changes to Integer). This is because polymorphic code is slower than code that has concrete types. Try :set -XNoMonomorphismRestriction, then test it again. It may be that different versions of ghci have a different default for that pragma. On Fri, Jan 27, 2017 at 6:23 AM, Jan Erik Moström <li...@mostrom.pp.se> wrote: > Hi, > > Here is something that I don't understand, why does the named value have a > different type than just the value itself? > > Prelude> let f x = x * x > Prelude> :t f > f :: Num a => a -> a > Prelude> :t [f] > [f] :: Num a => [a -> a] > Prelude> let g = [f] > Prelude> :t g > g :: [Integer -> Integer] > > = jem > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 2 Date: Fri, 27 Jan 2017 16:17:48 +0100 From: Daniel Trstenjak <daniel.trsten...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Change in type that I don't understand Message-ID: <20170127151748.GA9028@octa> Content-Type: text/plain; charset=us-ascii On Fri, Jan 27, 2017 at 08:35:08AM -0500, David McBride wrote: > If you have the Monomorphism restriction set, it will choose types > based on the type defaulting rules (Num changes to Integer). This is > because polymorphic code is slower than code that has concrete types. But why didn't the defaulting rules have been applied for both: 'f' and 'g'? Greetings, Daniel ------------------------------ Message: 3 Date: Fri, 27 Jan 2017 10:43:28 -0500 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Change in type that I don't understand Message-ID: <CAN+Tr43JsxKjf5R5yEWYTBu_MCN2RXbmHJDRhtC=kge5ock...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Because f has an argument x, and g doesn't. On Fri, Jan 27, 2017 at 10:17 AM, Daniel Trstenjak <daniel.trsten...@gmail.com> wrote: > > On Fri, Jan 27, 2017 at 08:35:08AM -0500, David McBride wrote: >> If you have the Monomorphism restriction set, it will choose types >> based on the type defaulting rules (Num changes to Integer). This is >> because polymorphic code is slower than code that has concrete types. > > But why didn't the defaulting rules have been applied for both: 'f' and 'g'? > > Greetings, > Daniel > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 4 Date: Fri, 27 Jan 2017 10:53:47 -0500 From: David McBride <toa...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Change in type that I don't understand Message-ID: <can+tr422twzxrhmiwc2cctmisuk0_309ncampv9i9devvea...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 Sorry let me elaborate. The type of f depends on its argument. The argument could be anything that the caller passes in so long as it is an instance of Num. If the user passes in Int or Integer or Float, it has to handle all those cases. It can't just type restrict the argument to Int, that is likely not what the user wanted. If he had he would have type restricted it himself. g on the other hand has complete control over its own type. If mm restriction is enabled and there is no type declaration then it is reasonable for it to default to a concrete type so that it only has to generate only one possible code path. If it isn't enabled then it will try to be as polymorphic as possible, at the cost of being flexible enough to return any type that is an instance of Num. On Fri, Jan 27, 2017 at 10:17 AM, Daniel Trstenjak <daniel.trsten...@gmail.com> wrote: > > On Fri, Jan 27, 2017 at 08:35:08AM -0500, David McBride wrote: >> If you have the Monomorphism restriction set, it will choose types >> based on the type defaulting rules (Num changes to Integer). This is >> because polymorphic code is slower than code that has concrete types. > > But why didn't the defaulting rules have been applied for both: 'f' and 'g'? > > Greetings, > Daniel > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ------------------------------ Message: 5 Date: Fri, 27 Jan 2017 17:29:09 +0100 From: Daniel Trstenjak <daniel.trsten...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] Change in type that I don't understand Message-ID: <20170127162909.GB11209@octa> Content-Type: text/plain; charset=us-ascii Thank you for the nice explanation! Greetings, Daniel ------------------------------ Message: 6 Date: Fri, 27 Jan 2017 23:09:07 +0100 From: sasa bogicevic <brutalles...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: [Haskell-beginners] applicative instance Message-ID: <7bea3c9a-ba94-40a9-9514-e17f4c1f8...@gmail.com> Content-Type: text/plain; charset=us-ascii What is wrong with my applicative instance for custom List type ? http://lpaste.net/351723 data List a = Nil | Cons a (List a) deriving (Eq, Show) instance Applicative List where pure x = Cons x Nil Nil <*> _ = Nil _ <*> Nil = Nil (Cons x xy) <*> (Cons z dy) = Cons (x z) (xy <*> dy) Prelude> let functions = Cons (+1) (Cons (*2) Nil) Prelude> let values = Cons 1 (Cons 2 Nil) Prelude> functions <*> values Cons 2 (Cons 3 (Cons 2 (Cons 4 Nil))) -- I get Cons 2 (Cons 4 Nil) what is wrong with my Applicative instance ? { name: Bogicevic Sasa phone: +381606006200 } ------------------------------ Message: 7 Date: Fri, 27 Jan 2017 22:17:35 +0000 From: Benjamin Edwards <edwards.b...@gmail.com> To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell <beginners@haskell.org> Subject: Re: [Haskell-beginners] applicative instance Message-ID: <CAN6k4nhYfCKyp327A0uJqqQXbb39iCCpAi1gMZsOPk=-p5c...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" You are zipping rather than taking the cross product. Ben On Fri, 27 Jan 2017, 22:09 sasa bogicevic, <brutalles...@gmail.com> wrote: > What is wrong with my applicative instance for custom List type ? > > http://lpaste.net/351723 > > data List a = Nil | Cons a (List a) deriving (Eq, Show) > > > > instance Applicative List where > pure x = Cons x Nil > Nil <*> _ = Nil > _ <*> Nil = Nil > (Cons x xy) <*> (Cons z dy) = Cons (x z) (xy <*> dy) > > Prelude> let functions = Cons (+1) (Cons (*2) Nil) > Prelude> let values = Cons 1 (Cons 2 Nil) > Prelude> functions <*> values > Cons 2 (Cons 3 (Cons 2 (Cons 4 Nil))) -- I get Cons 2 (Cons 4 Nil) what > is wrong with my Applicative instance ? > > > { > name: Bogicevic Sasa > phone: +381606006200 > } > > > > _______________________________________________ > 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/20170127/8ab8b4ad/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 103, Issue 23 ******************************************