# Proposal: Num instance for (a -> b)

19 messages
Open this post in threaded view
|

## Proposal: Num instance for (a -> b)

 relevant reddit comment thread: https://www.reddit.com/r/haskell/comments/9vtis5/the_universe_of_discourse_i_hate_the_environment/e9f1lea?utm_source=reddit-androidinstance Num b => Num (a -> b) where  f + g = \x -> f x + g x  f * g = \x -> f x * g x  f - g = \x -> f x - g x  negate f = \x -> negate (f x)  abs f = \x -> abs (f x)  signum f = \x -> signum (f x)  fromInteger i = \x -> fromInteger (f x) _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 On Sat, 10 Nov 2018, Daniel Cartwright wrote: > relevant reddit comment thread:https://www.reddit.com/r/haskell/comments/9vtis5/the_universe_of_discourse_i_hate_the_environment/e9f1lea?utm_so> urce=reddit-android https://wiki.haskell.org/index.php?title=Num_instance_for_functions&oldid=36632In short: It would make 2(x+y) no longer a type error but equivalent to 2. We would lose a lot of type safety for little syntactic gain. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 In reply to this post by chessai . I'm +1 on this, since it is conventional to write addition (and others) over function as such in most math textbooks.2018년 11월 11일 (일) 13:48에 Daniel Cartwright <[hidden email]>님이 작성:relevant reddit comment thread: https://www.reddit.com/r/haskell/comments/9vtis5/the_universe_of_discourse_i_hate_the_environment/e9f1lea?utm_source=reddit-androidinstance Num b => Num (a -> b) where  f + g = \x -> f x + g x  f * g = \x -> f x * g x  f - g = \x -> f x - g x  negate f = \x -> negate (f x)  abs f = \x -> abs (f x)  signum f = \x -> signum (f x)  fromInteger i = \x -> fromInteger (f x) _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 In reply to this post by Henning Thielemann On Sun, 11 Nov 2018, Henning Thielemann wrote: > On Sat, 10 Nov 2018, Daniel Cartwright wrote: > >> relevant reddit comment >> thread:https://www.reddit.com/r/haskell/comments/9vtis5/the_universe_of_discourse_i_hate_the_environment/e9f1lea?utm_so>> urce=reddit-android > > https://wiki.haskell.org/index.php?title=Num_instance_for_functions&oldid=36632> > In short: It would make 2(x+y) no longer a type error but equivalent to 2. We > would lose a lot of type safety for little syntactic gain. Btw. before adding more Wat instances please implement the GHC warning about such instances:     https://ghc.haskell.org/trac/ghc/ticket/11796_______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 On Sun, 11 Nov 2018, Dannyu NDos wrote: > I suggest adding this as an orphan instance (Like Show (a -> b)) in a seperate module (say, Numeric.Function). https://hackage.haskell.org/package/NumInstancesIt would not save much, because in a reasonably big project you will somewhen import a package that transitively depends on the module. E.g. 'diagrams-canvas' depends on NumInstances. _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 In reply to this post by Henning Thielemann On 11/11/18, Henning Thielemann <[hidden email]> wrote: > > On Sun, 11 Nov 2018, Henning Thielemann wrote: > >> On Sat, 10 Nov 2018, Daniel Cartwright wrote: >> >>> relevant reddit comment >>> thread:https://www.reddit.com/r/haskell/comments/9vtis5/the_universe_of_discourse_i_hate_the_environment/e9f1lea?utm_so>>> urce=reddit-android >> >> https://wiki.haskell.org/index.php?title=Num_instance_for_functions&oldid=36632>> >> In short: It would make 2(x+y) no longer a type error but equivalent to 2. >> We >> would lose a lot of type safety for little syntactic gain. > > Btw. before adding more Wat instances please implement the GHC warning > about such instances: >     https://ghc.haskell.org/trac/ghc/ticket/11796This is my feeling as well. Tom _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 In reply to this post by Oleg Grenrus Oleg Grenrus wrote: > Monoid doesn't have fromInteger -like function. For example, we don't have FromString b => FromString (a -> b) instance. Monoid does have `mempty` though, with the unfortunate property that   mempty [1,2] /= mempty `mappend` [1,2] But I'm less worried about this than in the case of Num; I occasionally copy formulas from a CAS into Haskell code and then add the missing * operations manually; I estimate that about half of the time I miss one instance and am rescued by the type checker. So to me, `2 (x + y)` no longer being a type error would have practical implications. -1 on the proposal from me. Cheers, Bertram _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 In reply to this post by chessai . Daniel Cartwright <[hidden email]> writes: > ANum seems to be just Data.Monoid.Ap. > Also, I can see not wanting to worsen the error messages, though it is > worth pointing out that we already have a Monoid instance with the same > semantics, and a similar potential for confusing error messages. The existence of a previous bad decision doesn’t seem to me to be a good reason to make another one. -- Jón Fairbairn                                 [hidden email] http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2014-04-05) _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
Open this post in threaded view
|

## Re: Proposal: Num instance for (a -> b)

 I'm not sure I would label it a bad decision, but the concerns here make sense.On Mon, Nov 12, 2018, 5:16 AM Jon Fairbairn <[hidden email] wrote:Daniel Cartwright <[hidden email]> writes: > ANum seems to be just Data.Monoid.Ap. > Also, I can see not wanting to worsen the error messages, though it is > worth pointing out that we already have a Monoid instance with the same > semantics, and a similar potential for confusing error messages. The existence of a previous bad decision doesn’t seem to me to be a good reason to make another one. -- Jón Fairbairn                                 [hidden email] http://www.chaos.org.uk/~jf/Stuff-I-dont-want.html  (updated 2014-04-05) _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
 In reply to this post by chessai . > relevant reddit comment thread: ...`Are you people completely nuts? Haven't you wreaked enough havoc with the Foldable Traversable Piffle?Why ref pointy-headed discussion on reddit when you could also ref far more frequent complaints:https://blog.plover.com/prog/haskell/type-errors.html"I think there must be something really wrong with the language design here. I don't know exactly what it is, but I think someone must have made the wrong tradeoff at some point."https://blog.plover.com/prog/haskell/evaluation-functor-2.htmlhttps://blog.plover.com/prog/haskell/evaluation-functor.html(It's by no means only that author complaining; it's just that was easiest to grab.)No, EKmett, including `length` in `Foldable` with a `((,) a)` instance is a lot more serious than "somewhat unfortunate".> At what point is it better to put "weird" stuff into its own libraries (or `newtype`s) and keep `base` clean?Always the standard Prelude should be clean of "weird" stuff. So that beginners don't have to go round the houses to exclude the standard and get a sensible Prelude. A beginner has more than enough to cope with without piling the import mechanism on them.Whereas it's no burden on the pointy-heads to import WeirdPrelude.If the CLC process were to do anything useful, I'd expect yous to be organising that. And then I could leave yew lot to turn your Haskell into Perl, where any composition of symbols can acquire some meaning.As it is, the only reason I monitor the Libraries list is to complain about proposals for nuttiness.AntC` _______________________________________________ Libraries mailing list [hidden email] http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries