tag:blogger.com,1999:blog-8288194986820249216.post4867971557617554243..comments2024-03-22T05:09:17.789-07:00Comments on Abstract Heresies: Replies to commentsJoe Marshallhttp://www.blogger.com/profile/03233353484280456977noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-8288194986820249216.post-70829917361458526402011-02-01T22:08:13.211-08:002011-02-01T22:08:13.211-08:00Here's the Haskell type for +:
(+) :: (Num ...Here's the Haskell type for +:<br /><br /> (+) :: (Num a) => a -> a -> a<br /><br />You can make new instances of the Num type class (just like you can write your own instances of the Monad class). A silly example:<br /><br />data Foo = Foo<br /> deriving (Show,Eq)<br /><br />instance Num Foo where<br /> (+) Foo Foo = Foo<br /><br />With these definitions, the following is a valid expression:<br /><br /> Foo + FooPaul Stecklerhttps://www.blogger.com/profile/13416750891822431224noreply@blogger.comtag:blogger.com,1999:blog-8288194986820249216.post-63039299931582132582011-01-31T13:23:13.731-08:002011-01-31T13:23:13.731-08:00> Does Haskell allow you to add user defined su...> Does Haskell allow you to add user defined subtypes to the built-in number types?<br /><br />Only knowing Haskell, I'm not sure what you mean in Haskell terms.<br /><br />If I disliked the Num instance for Integer, say, I could define a newtype for Integer ('newtype MyInteger = MyInteger Integer' and then define a new instance of Num ('instance MyInteger Num where (+) = ...').gwernhttps://www.blogger.com/profile/18349479103216755952noreply@blogger.com