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: Problems defining a type with a multiplication function (Joe Fredette) 2. Re: Problems defining a type with a multiplication function (John Dorsey) 3. Re: Problems defining a type with a multiplication function (Brent Yorgey) 4. problem running yi on OS X (Richard Talley) 5. hide Perl code inside Haskell program (Hong Yang) 6. Re: hide Perl code inside Haskell program (Jos? Prous) 7. Parsec 2 and Parsec 3 (John Velman) 8. Re: Parsec 2 and Parsec 3 (Chadda? Fouch?) 9. Re: Parsec 2 and Parsec 3 (John Velman) ---------------------------------------------------------------------- Message: 1 Date: Wed, 9 Sep 2009 17:05:04 -0400 From: Joe Fredette <jfred...@gmail.com> Subject: Re: [Haskell-beginners] Problems defining a type with a multiplication function To: Amy de Buitl?ir <a...@nualeargais.ie> Cc: beginners@haskell.org Message-ID: <27841e46-cebb-4859-a40f-c62f521c3...@gmail.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed; delsp=yes You need to write an instance of the Num class, eg instance Num Quaternion where (Q a b c d) + (Q e f g h) = ... (Q a b c d) * (Q e f g h) = ... etc This allows Haskell to overload things like numbers. You seem to be headed in the right direction w/ your type signature, except (*) has type Num a => a -> a -> a Which means "For any type `a` that is an instance of the type class `Num`, this is a closed binary function on that type" HTH /Joe On Sep 9, 2009, at 4:51 PM, Amy de Buitléir wrote: > I'm trying to define a Quaternion, which is sort of a four-element > vector with special rules for multiplication. > > ----- Quaternion.hs ----- > data Quaternion = Quaternion Double Double Double Double > deriving (Show) > > (*) :: (Quaternion a) => a -> a -> a > (*) (Quaternion w1 x1 y1 z1) (Quaternion w2 x2 y2 z2) = Quaternion w > x y z > where w = w1*w2 - x1*x2 - y1*y2 - z1*z2 > x = x1*w2 + w1*x2 + y1*z2 - z1*y2 > y = w1*y2 - x1*z2 + y1*w2 + z1*x2 > z = w1*z2 + x1*y2 - y1*x2 + z1*w2 > > ----- end code ----- > > When I try to load this into ghci, I get: > > Quaternion.hs:6:13: > Ambiguous occurrence `*' > It could refer to either `Main.*', defined at Quaternion.hs:5:0 > or `Prelude.*', imported from Prelude > > ... and lots more messages like that. I understand roughly what the > message means, but I don't know how to tell it that when I use "*" > within the definition, I just want ordinary multiplication. Thanks > in advance for any help! > > Amy > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners ------------------------------ Message: 2 Date: Wed, 9 Sep 2009 17:10:38 -0400 From: John Dorsey <hask...@colquitt.org> Subject: Re: [Haskell-beginners] Problems defining a type with a multiplication function To: beginners@haskell.org Message-ID: <20090909211038.gj14...@colquitt.org> Content-Type: text/plain; charset=us-ascii Amy, > instance Num Quaternion where Use this (from Joe's email), and not > instance Num (Quaternion a) this (from mine). I had skimmed your code too quickly and wrote the above in error because I'd thought you had make Quaternion parametric. Unless you want the parametricity, as in: data Quaternion a = Quaternion a a a a class (Num a) => Num (Quaternion a) where ... Cheers, John ------------------------------ Message: 3 Date: Wed, 9 Sep 2009 17:50:46 -0400 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] Problems defining a type with a multiplication function To: beginners@haskell.org Message-ID: <20090909215046.ga10...@seas.upenn.edu> Content-Type: text/plain; charset=iso-8859-1 On Wed, Sep 09, 2009 at 09:51:34PM +0100, Amy de Buitléir wrote: > > ----- Quaternion.hs ----- > data Quaternion = Quaternion Double Double Double Double > deriving (Show) > > (*) :: (Quaternion a) => a -> a -> a Also, I should point out that the '(blah) => ...' syntax is only for type *classes*; Quaternion is just a data type so it doesn't make sense to use it in this way. The type signature instead ought to just say (*) :: Quaternion -> Quaternion -> Quaternion although as others have pointed out you will still get the error about (*) being ambiguous. You can either implement Num as others have suggested, or just use a different name for quaternion multiplication, such as, say, (*!). -Brent ------------------------------ Message: 4 Date: Wed, 9 Sep 2009 21:50:13 -0600 From: Richard Talley <rich.tal...@gmail.com> Subject: [Haskell-beginners] problem running yi on OS X To: beginners@haskell.org Message-ID: <cda4d1a40909092050x2c61fe17r6fa43d9699bbf...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" I'm running OS X 10.5.8 on Intel. I installed GHC 6.10.4 and the Haskell Platform 2009.2.0.2 with no problem (thanks to everybody who made this so easy on OS X). The yi editor seems very interesting, so I installed it with 'cabal install yi' (after running 'cabal update'). That went OK (with some warnings about deprecated GHC features) and I was able to run yi which I found in ~/.cabal/bin Pressing h for help gave me a sample configuration file for yi which I edited to use cua keybindings and the (experimental) cocoa gui. Now when I tried to run yi again, I got this: Recompiling custom yi Launching custom yi: "/Users/rbtalley/.yi/yi-i386-darwin" yi: /Users/rbtalley/.yi/yi-i386-darwin: executeFile: does not exist (No such file or directory) Any suggestions? -- Rich -- Dealing with failure is easy: Work hard to improve. Success is also easy to handle: You've solved the wrong problem. Work hard to improve. -- Alan Perlis -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090909/fb248860/attachment-0001.html ------------------------------ Message: 5 Date: Thu, 10 Sep 2009 12:24:26 -0500 From: Hong Yang <hyang...@gmail.com> Subject: [Haskell-beginners] hide Perl code inside Haskell program To: beginners@haskell.org Message-ID: <f31db34d0909101024l21aef87fya9190e994cf11...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" I was trying to hide Perl code inside Haskell program like the following: > module Main where > import System.Environment (getArgs) > import System.Cmd > main = do > args <- getArgs > rawSystem pl args > where pl = "#!/usr/bin/perl\n" ++ > "print \"testing ...\n\";" The program can run, but generates no output at all. Can someone tell me any other tricks which might be missing? (Do we need to use pipe here?) Thanks, Hong -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090910/0259444b/attachment-0001.html ------------------------------ Message: 6 Date: Thu, 10 Sep 2009 13:45:33 -0400 From: Jos? Prous <hien...@gmail.com> Subject: Re: [Haskell-beginners] hide Perl code inside Haskell program To: Hong Yang <hyang...@gmail.com> Cc: beginners@haskell.org Message-ID: <fe6e81eb0909101045n1c344b5asb8451cd4679b8...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" you are putting the perl script as the name of the command you can do something like: rawSystem "perl" ["-e","print \"testing ...\n\";" ] this is equivalent to call in the shell: perl -e "print \"testing ...\";" (sorry Hong I din't put reply to all in the fist mail) On Thu, Sep 10, 2009 at 1:24 PM, Hong Yang <hyang...@gmail.com> wrote: > I was trying to hide Perl code inside Haskell program like the following: > > > module Main where > > > import System.Environment (getArgs) > > import System.Cmd > > > main = do > > args <- getArgs > > rawSystem pl args > > where pl = "#!/usr/bin/perl\n" ++ > > "print \"testing ...\n\";" > > The program can run, but generates no output at all. Can someone tell me > any other tricks which might be missing? (Do we need to use pipe here?) > > Thanks, > > Hong > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20090910/2c07e9de/attachment-0001.html ------------------------------ Message: 7 Date: Thu, 10 Sep 2009 12:36:54 -0700 From: John Velman <vel...@cox.net> Subject: [Haskell-beginners] Parsec 2 and Parsec 3 To: Haskell Beginners <beginners@haskell.org> Message-ID: <20090910193654.ga1...@cox.net> Content-Type: text/plain; charset=us-ascii I've just started picking up Haskell where I left off a couple years ago when I switched from Linux to OS X (and some other things interfered with continuing my Haskell projects). I was using Parsec at the time -- must have been Parsec 2. When I loaded HOC it seemed to depend on Parsec 3, so I installed Parsec 3. Now -- suppose I want to use Parsec 2 for my own work. Is there a reasonably easy way to install Parsec 2 as, say Parsec2 and have both? Thanks, John Velman ------------------------------ Message: 8 Date: Fri, 11 Sep 2009 08:44:39 +0200 From: Chadda? Fouch? <chaddai.fou...@gmail.com> Subject: Re: [Haskell-beginners] Parsec 2 and Parsec 3 To: John Velman <vel...@cox.net>, Haskell Beginners <beginners@haskell.org> Message-ID: <e9350eaf0909102344y6783be7ah17cc34b2c792f...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Thu, Sep 10, 2009 at 9:36 PM, John Velman <vel...@cox.net> wrote: > I've just started picking up Haskell where I left off a couple years ago > when I switched from Linux to OS X (and some other things interfered with > continuing my Haskell projects). > > I was using Parsec at the time -- must have been Parsec 2. > > When I loaded HOC it seemed to depend on Parsec 3, so I installed Parsec 3. > > Now -- suppose I want to use Parsec 2 for my own work. > > Is there a reasonably easy way to install Parsec 2 as, say Parsec2 and have > both? You can install several version of a package, it's not a problem. You then have to say which version to use when compiling your code (by default it uses the latest version). If you want to install parsec3 for the code that may require it and use parsec2 automatically when compiling your own code, use ghc-pkg to hide the version 3. -- Jedaï ------------------------------ Message: 9 Date: Fri, 11 Sep 2009 09:01:58 -0700 From: John Velman <vel...@cox.net> Subject: Re: [Haskell-beginners] Parsec 2 and Parsec 3 To: Haskell Beginners <beginners@haskell.org> Message-ID: <20090911160158.ga...@cox.net> Content-Type: text/plain; charset=iso-8859-1 Thanks, Jedaï. Very helpful, John V. On Fri, Sep 11, 2009 at 08:44:39AM +0200, Chaddaï Fouché wrote: > On Thu, Sep 10, 2009 at 9:36 PM, John Velman <vel...@cox.net> wrote: > > I've just started picking up Haskell where I left off a couple years ago > > when I switched from Linux to OS X (and some other things interfered with > > continuing my Haskell projects). > > > > I was using Parsec at the time -- must have been Parsec 2. > > > > When I loaded HOC it seemed to depend on Parsec 3, so I installed Parsec 3. > > > > Now -- suppose I want to use Parsec 2 for my own work. > > > > Is there a reasonably easy way to install Parsec 2 as, say Parsec2 and have > > both? > > You can install several version of a package, it's not a problem. You > then have to say which version to use when compiling your code (by > default it uses the latest version). If you want to install parsec3 > for the code that may require it and use parsec2 automatically when > compiling your own code, use ghc-pkg to hide the version 3. > > -- > Jedaï ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 15, Issue 7 ****************************************