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. index too large (Nathan M. Holden) 2. Re: index too large (Daniel Fischer) 3. Dynamic libraries not of required architecture when installing via cabal (Snow Leopard) (Malthe J?rgensen) 4. Re: Dynamic libraries not of required architecture when installing via cabal (Snow Leopard) (Brandon S. Allbery KF8NH) 5. Functor question. (Phillip Pirrip) 6. Re: Functor question. (Alexander Dunlap) 7. Re: Functor question. (Phillip Pirrip) ---------------------------------------------------------------------- Message: 1 Date: Thu, 12 Nov 2009 21:55:40 -0500 From: "Nathan M. Holden" <nathanmhol...@gmail.com> Subject: [Haskell-beginners] index too large To: beginners@haskell.org Message-ID: <200911122155.40162.nathanmhol...@gmail.com> Content-Type: Text/Plain; charset="us-ascii" I've been working on a quick program that acts (vaguely) like a console, lets me type notes and outputs them in a .tex file. I figure it's not that complicated, but it uses a vaguely n-ary structure, so that I can have headers and sub-notes, which loos like: data Note = N { nTitle :: {Char}, nBody :: {Char}, nFormat :: Format, subs :: [Note] | E [Char] Format's just a collection of preset formats, so I don't have to dynamically handle that (since I didn't need to for my uses). Anyways, for whatever reason, sometimes while adding notes, it sends me an error: Prelude.(!!): index too large My only 2 uses of that are in getFullName :: [Note] -> [Int] -> [Char] getFullName d [] = "/" getFullName d (x:xs) = "/" ++ getPartName (d!!x) ++ getFullName (subs (d!!x)) xs and moveIn :: [Note] -> [Int] -> [Char] -> Int -> [Int] moveIn [] i m c = reverse i moveIn ((N dt db df du):ds) [] m c = if matchNote (N dt db df du) m then c:[] else moveIn ds [] m (c+1) moveIn n i m c = last i : ((moveIn (subs (n!!(last i)))) (allButLast i) m 0) where the [Int] is the variable I use to track where in the tree I am. Since I'm not moving into a Note that doesn't exist, and the display shouldn't be changing, what could be the problem? This is probably too in-depth a question, now that I think about it... ------------------------------ Message: 2 Date: Fri, 13 Nov 2009 07:00:43 +0100 From: Daniel Fischer <daniel.is.fisc...@web.de> Subject: Re: [Haskell-beginners] index too large To: beginners@haskell.org Message-ID: <200911130700.43557.daniel.is.fisc...@web.de> Content-Type: text/plain; charset="iso-8859-1" Am Freitag 13 November 2009 03:55:40 schrieb Nathan M. Holden: > I've been working on a quick program that acts (vaguely) like a console, > lets me type notes and outputs them in a .tex file. I figure it's not that > complicated, but it uses a vaguely n-ary structure, so that I can have > headers and sub-notes, which loos like: > > data Note = N { > nTitle :: {Char}, > nBody :: {Char}, > nFormat :: Format, > subs :: [Note] > > | E [Char] > > Format's just a collection of preset formats, so I don't have to > dynamically handle that (since I didn't need to for my uses). > > Anyways, for whatever reason, sometimes while adding notes, it sends me an > error: Prelude.(!!): index too large Obviously, sometimes you call list!!index with index > (length list - 1). Are you aware that the indices are 0-based? If it's not that, one would have to analyse the code, but it would be better to see more of it for that. ------------------------------ Message: 3 Date: Sun, 15 Nov 2009 17:42:39 +0100 From: Malthe J?rgensen <malth...@hotmail.com> Subject: [Haskell-beginners] Dynamic libraries not of required architecture when installing via cabal (Snow Leopard) To: beginners@haskell.org Message-ID: <blu0-smtp480cb9db13aa710dd31191e3...@phx.gbl> Content-Type: text/plain; charset="us-ascii" I'm on Snow Leopard, so I've read numerous posts on the subject of GHC and it's Snow Leopard (non-)compatibility. I've got most things working - I can do a 'cabal update' - something that gave errors before. GHC itself seems to be working fine. I want to install the SDL package from Hackage, which I first tried doing like this: 'cabal install sdl' which gives a bunch of warnings, all looking like this 'ld: warning: in /opt/local/lib/libSDL.dylib, file is not of required architecture' with 'libSDL.dylib' replaced with various *.a and *.dylib files I then found this in a Usenet post about Snow Leopard breaking GHC: -- Once cabal works, options --ld-option=-m32 (and also --gcc-option=- m32) may be used. These options may also be passed to "./Setup configure" And tried this: (I think maybe my problem is that I'm not passing these flags correctly to cabal) 'cabal install sdl --ld-options="-arch i386" --gcc-option=-m32 -- reinstall' Well I get the same errors, well warnings actually. Can I just ignore these warnings? When compiling my small sample code: import Prelude import Graphics.UI.SDL as SDL main = do SDL.init [InitEverything] setVideoMode 640 480 32 [] I again get the warnings: ld: warning: in /opt/local/lib/libSDL.dylib, file is not of required architecture ld: warning: in /opt/local/lib/libSDLmain.a, file is not of required architecture and then a bunch of undefined symbols such as: _SDL_Init _SDL_SetClipRect Well this post basically based on the assumption that the warnings are breaking the SDL library and thereby keeping my code from compiling - so how do I fix those warnings? - Sorry for the long mail Malthe -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.haskell.org/pipermail/beginners/attachments/20091115/94a3e4b3/attachment-0001.html ------------------------------ Message: 4 Date: Sun, 15 Nov 2009 20:27:48 -0500 From: "Brandon S. Allbery KF8NH" <allb...@ece.cmu.edu> Subject: Re: [Haskell-beginners] Dynamic libraries not of required architecture when installing via cabal (Snow Leopard) To: Malthe J?rgensen <malth...@hotmail.com> Cc: beginners@haskell.org Message-ID: <fd2da774-4257-46c7-a923-fe9ea1e11...@ece.cmu.edu> Content-Type: text/plain; charset="iso-8859-1" Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: PGP.sig Type: application/pgp-signature Size: 195 bytes Desc: This is a digitally signed message part Url : http://www.haskell.org/pipermail/beginners/attachments/20091115/85f752b7/PGP-0001.bin ------------------------------ Message: 5 Date: Sun, 15 Nov 2009 22:50:05 -0500 From: Phillip Pirrip <ppir...@gmail.com> Subject: [Haskell-beginners] Functor question. To: beginners@haskell.org Message-ID: <b3d87c85-fac0-48c8-b36c-e36aa2580...@gmail.com> Content-Type: text/plain; charset=us-ascii Hi, When I define my data as fellow, data Moo a = Moo a deriving (Show) instance Functor Moo where fmap f (Moo a) = Moo (f a) GHC gives me no problem. Then I add something, data (Num a) => Moo a = Moo a deriving (Show) instance Functor Moo where fmap f (Moo a) = Moo (f a) Now GHC gives me the follow error - see bellow. What is the reason behind this? What should I do to correct this? thx, // matFun_v2.hs:16:12: Could not deduce (Num a) from the context () arising from a use of `Moo' at matFun_v2.hs:16:12-14 Possible fix: add (Num a) to the context of the type signature for `fmap' In the pattern: Moo a In the definition of `fmap': fmap f (Moo a) = Moo (f a) In the instance declaration for `Functor Moo' matFun_v2.hs:16:21: Could not deduce (Num b) from the context () arising from a use of `Moo' at matFun_v2.hs:16:21-29 Possible fix: add (Num b) to the context of the type signature for `fmap' In the expression: Moo (f a) In the definition of `fmap': fmap f (Moo a) = Moo (f a) In the instance declaration for `Functor Moo' ------------------------------ Message: 6 Date: Sun, 15 Nov 2009 20:07:36 -0800 From: Alexander Dunlap <alexander.dun...@gmail.com> Subject: Re: [Haskell-beginners] Functor question. To: Phillip Pirrip <ppir...@gmail.com> Cc: beginners@haskell.org Message-ID: <57526e770911152007y54165145veae92d4afd552...@mail.gmail.com> Content-Type: text/plain; charset=UTF-8 On Sun, Nov 15, 2009 at 7:50 PM, Phillip Pirrip <ppir...@gmail.com> wrote: > > Hi, > > When I define my data as fellow, > > data Moo a = Moo a > Â Â Â Â Â Â deriving (Show) > > instance Functor Moo where > Â fmap f (Moo a) = Moo (f a) > > GHC gives me no problem. Â Then I add something, > > data (Num a) => Moo a = Moo a > Â Â Â Â Â Â deriving (Show) > > instance Functor Moo where > Â fmap f (Moo a) = Moo (f a) > > Now GHC gives me the follow error - see bellow. > > What is the reason behind this? Â What should I do to correct this? > > thx, > > // > > matFun_v2.hs:16:12: > Â Could not deduce (Num a) from the context () > Â Â arising from a use of `Moo' at matFun_v2.hs:16:12-14 > Â Possible fix: > Â Â add (Num a) to the context of the type signature for `fmap' > Â In the pattern: Moo a > Â In the definition of `fmap': fmap f (Moo a) = Moo (f a) > Â In the instance declaration for `Functor Moo' > > matFun_v2.hs:16:21: > Â Could not deduce (Num b) from the context () > Â Â arising from a use of `Moo' at matFun_v2.hs:16:21-29 > Â Possible fix: > Â Â add (Num b) to the context of the type signature for `fmap' > Â In the expression: Moo (f a) > Â In the definition of `fmap': fmap f (Moo a) = Moo (f a) > Â In the instance declaration for `Functor Moo' > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > Your datatype Moo cannot be an instance of Functor because Moo cannot contain all types. fmap takes a function of type (a -> b), which means that the function can be from *any* type a to *any* type b, and produces a function of type (f a -> f b), which in your case means Moo a -> Moo b. But the function fmap f (Moo x) = Moo (f x) does not have type "a -> b"; it has type "(Num a, Num b) => a -> b", since if you can have a type Moo a, a must be an instance of Num. In general, people recommend against using constriants on datatypes, recommending instead to put those constraints on the functions that operate on the datatypes. I'm not quite sure why that is, though. Alex ------------------------------ Message: 7 Date: Sun, 15 Nov 2009 23:34:39 -0500 From: Phillip Pirrip <ppir...@gmail.com> Subject: Re: [Haskell-beginners] Functor question. To: Alexander Dunlap <alexander.dun...@gmail.com> Cc: beginners@haskell.org Message-ID: <9b0f47a5-1d25-4144-800d-b91a94d6b...@gmail.com> Content-Type: text/plain; charset=us-ascii On 2009-11-15, at 11:07 PM, Alexander Dunlap wrote: > On Sun, Nov 15, 2009 at 7:50 PM, Phillip Pirrip <ppir...@gmail.com> wrote: >> >> Hi, >> >> When I define my data as fellow, >> >> data Moo a = Moo a >> deriving (Show) >> >> instance Functor Moo where >> fmap f (Moo a) = Moo (f a) >> >> GHC gives me no problem. Then I add something, >> >> data (Num a) => Moo a = Moo a >> deriving (Show) >> >> instance Functor Moo where >> fmap f (Moo a) = Moo (f a) >> >> Now GHC gives me the follow error - see bellow. >> >> What is the reason behind this? What should I do to correct this? >> >> thx, >> >> // >> >> matFun_v2.hs:16:12: >> Could not deduce (Num a) from the context () >> arising from a use of `Moo' at matFun_v2.hs:16:12-14 >> Possible fix: >> add (Num a) to the context of the type signature for `fmap' >> In the pattern: Moo a >> In the definition of `fmap': fmap f (Moo a) = Moo (f a) >> In the instance declaration for `Functor Moo' >> >> matFun_v2.hs:16:21: >> Could not deduce (Num b) from the context () >> arising from a use of `Moo' at matFun_v2.hs:16:21-29 >> Possible fix: >> add (Num b) to the context of the type signature for `fmap' >> In the expression: Moo (f a) >> In the definition of `fmap': fmap f (Moo a) = Moo (f a) >> In the instance declaration for `Functor Moo' >> _______________________________________________ >> Beginners mailing list >> Beginners@haskell.org >> http://www.haskell.org/mailman/listinfo/beginners >> > > Your datatype Moo cannot be an instance of Functor because Moo cannot > contain all types. fmap takes a function of type (a -> b), which means > that the function can be from *any* type a to *any* type b, and > produces a function of type (f a -> f b), which in your case means Moo > a -> Moo b. But the function fmap f (Moo x) = Moo (f x) does not have > type "a -> b"; it has type "(Num a, Num b) => a -> b", since if you > can have a type Moo a, a must be an instance of Num. > > In general, people recommend against using constriants on datatypes, > recommending instead to put those constraints on the functions that > operate on the datatypes. I'm not quite sure why that is, though. > > Alex Thanks Alex. That is very clear. I didn't expect that (Num a, Num b)=>a->b is actually different than a->b from the compiler point of view. I was under the assumption that the more constraint I put there the better for the compiler. //pip ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 17, Issue 16 *****************************************