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: tuple update (Thomas Davie) 2. Re: tuple update (Ovidiu Deac) 3. Re: tuple update (Brent Yorgey) 4. constant set (Ovidiu Deac) 5. Re: constant set (Ertugrul S?ylemez) 6. Re: tuple update (Ertugrul S?ylemez) 7. Problem with developing NCurses program (Aditya Manthramurthy) 8. Re: Problem with developing NCurses program (Aditya Manthramurthy) ---------------------------------------------------------------------- Message: 1 Date: Fri, 9 Mar 2012 19:23:50 +0000 From: Thomas Davie <tom.da...@gmail.com> Subject: Re: [Haskell-beginners] tuple update To: Brent Yorgey <byor...@seas.upenn.edu> Cc: beginners@haskell.org Message-ID: <be6f366f-a022-40df-a00d-eced96946...@gmail.com> Content-Type: text/plain; charset="us-ascii" first ofc also being known as fmap. Bob if (*ra4 != 0xffc78948) { return false; } On 9 Mar 2012, at 19:09, Brent Yorgey wrote: > On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote: >> Does anybody know if there are any functions like these in the Haskell >> libray? >> >> updateSnd f (x,y) -> (x, f y) >> >> updateFst f (x,y) -> (f x, y) > > Yes: 'first' and 'second' from Control.Arrow. > > -Brent > > _______________________________________________ > 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/20120309/2b4386f7/attachment-0001.htm> ------------------------------ Message: 2 Date: Fri, 9 Mar 2012 22:02:51 +0200 From: Ovidiu Deac <ovidiud...@gmail.com> Subject: Re: [Haskell-beginners] tuple update To: Thomas Davie <tom.da...@gmail.com> Cc: beginners@haskell.org Message-ID: <cakvse7up1kaxjvtmdbq5nx+pjyqhnuj1wrrov3cuf71p65a...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" @Bert first& second are exactly what I was looking for. Thanks. @Thomas: I'm not sure what you mean by fmap What I wanted is to do this: > let f = map $ first (*2) > f [(1,1),(2,2),(3,3),(4,4)] [(2,1),(4,2),(6,3),(8,4)] On Fri, Mar 9, 2012 at 9:23 PM, Thomas Davie <tom.da...@gmail.com> wrote: > first ofc also being known as fmap. > > Bob > > if (*ra4 != 0xffc78948) { return false; } > > > On 9 Mar 2012, at 19:09, Brent Yorgey wrote: > > On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote: > > Does anybody know if there are any functions like these in the Haskell > > libray? > > > updateSnd f (x,y) -> (x, f y) > > > updateFst f (x,y) -> (f x, y) > > > Yes: 'first' and 'second' from Control.Arrow. > > -Brent > > _______________________________________________ > Beginners mailing list > Beginners@haskell.org > http://www.haskell.org/mailman/listinfo/beginners > > > > _______________________________________________ > 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/20120309/f6c172a8/attachment-0001.htm> ------------------------------ Message: 3 Date: Fri, 9 Mar 2012 16:29:49 -0500 From: Brent Yorgey <byor...@seas.upenn.edu> Subject: Re: [Haskell-beginners] tuple update To: Thomas Davie <tom.da...@gmail.com> Cc: beginners@haskell.org Message-ID: <20120309212949.ga10...@seas.upenn.edu> Content-Type: text/plain; charset=us-ascii Actually it's second that is fmap. Prelude> :m +Control.Monad.Instances Control.Arrow Prelude Control.Monad.Instances Control.Arrow> fmap (*2) (1,3) (1,6) Prelude Control.Monad.Instances Control.Arrow> second (*2) (1,3) (1,6) -Brent On Fri, Mar 09, 2012 at 07:23:50PM +0000, Thomas Davie wrote: > first ofc also being known as fmap. > > Bob > if (*ra4 != 0xffc78948) { return false; } > > On 9 Mar 2012, at 19:09, Brent Yorgey wrote: > > > On Fri, Mar 09, 2012 at 09:07:24PM +0200, Ovidiu Deac wrote: > >> Does anybody know if there are any functions like these in the Haskell > >> libray? > >> > >> updateSnd f (x,y) -> (x, f y) > >> > >> updateFst f (x,y) -> (f x, y) > > > > Yes: 'first' and 'second' from Control.Arrow. > > > > -Brent > > > > _______________________________________________ > > Beginners mailing list > > Beginners@haskell.org > > http://www.haskell.org/mailman/listinfo/beginners > ------------------------------ Message: 4 Date: Sat, 10 Mar 2012 02:24:33 +0200 From: Ovidiu Deac <ovidiud...@gmail.com> Subject: [Haskell-beginners] constant set To: beginners <beginners@haskell.org> Message-ID: <cakvse7uxvk0pmbzet_2lhbknrtcasxqp2w1rwuzxqp02cjh...@mail.gmail.com> Content-Type: text/plain; charset="iso-8859-1" If I want to define a constant set in Python I would do this: class Colors: red = 1 blue=2 ... and then I use them like this: Colors.red, Colors.blue... Can I do something similar in Haskell? thanks -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/fd268ea6/attachment-0001.htm> ------------------------------ Message: 5 Date: Sat, 10 Mar 2012 02:04:08 +0100 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] constant set To: beginners@haskell.org Message-ID: <20120310020408.12df0...@angst.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" Ovidiu Deac <ovidiud...@gmail.com> wrote: > If I want to define a constant set in Python I would do this: > class Colors: > red = 1 > blue=2 > ... > > and then I use them like this: Colors.red, Colors.blue... > > Can I do something similar in Haskell? In Haskell this would usually be an abstract type: data Color = Red | Blue | ... You could then use functions to convert between integers and colors. fromColor :: Color -> Int toColor :: Int -> Maybe Color You could also derive an Enum instance and get the conversion functions 'fromEnum' and 'toEnum' for free, although in that case the 'toEnum' function is less safe (no Maybe): data Color = Red | Blue | ... deriving Enum fromEnum :: Color -> Int toEnum :: Int -> Color Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/2126ace7/attachment-0001.pgp> ------------------------------ Message: 6 Date: Sat, 10 Mar 2012 02:16:59 +0100 From: Ertugrul S?ylemez <e...@ertes.de> Subject: Re: [Haskell-beginners] tuple update To: beginners@haskell.org Message-ID: <20120310021659.1d935...@angst.streitmacht.eu> Content-Type: text/plain; charset="us-ascii" Ovidiu Deac <ovidiud...@gmail.com> wrote: > Does anybody know if there are any functions like these in the Haskell > libray? > > updateSnd f (x,y) -> (x, f y) > > updateFst f (x,y) -> (f x, y) While the function arrow mentioned by Brent is enough for many purposes, I just want to have mentioned Edward Kmett's amazing data-lens library, which provides prefab lenses for tuples: (3, 5) ^. fstLens = 3 (3, 5) ^. sndLens = 5 (fstLens ^= 4) (3, 5) = (4, 5) (sndLens ^= 4) (3, 5) = (3, 4) (fstLens ^%= f) (3, 5) = (f 3, 5) This is especially useful when your tuple is part of the implicit argument of a state monad (data-lens-fd package): access fstLens :: State (a, b) a -- starting state (3, 5) fstLens ~= 10 -- (10, 5) fstLens += 1 -- (11, 5) fstLens %= negate -- (-11, 5) focus fstLens $ do -- Do something with only the fst value here. Greets, Ertugrul -- nightmare = unsafePerformIO (getWrongWife >>= sex) http://ertes.de/ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 836 bytes Desc: not available URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/4a6589cd/attachment-0001.pgp> ------------------------------ Message: 7 Date: Sat, 10 Mar 2012 12:50:17 +0530 From: Aditya Manthramurthy <aditya....@gmail.com> Subject: [Haskell-beginners] Problem with developing NCurses program To: beginners@haskell.org Message-ID: <cac_me96ooqeujdvrfcd7ozk6ylbwr50r5lrx6twtvbgeosm...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" HI, I am learning haskell by writing small programs. In this instance I want to write a program using the haskell binding of the NCurses library. Here is the (rather simple) code: import UI.NCurses main = do putStrLn "Hello World" When I try to run it: $ runhaskell cursesprog.hs cursesprog.hs: <command line>: can't load .so/.DLL for: ncursesw (/usr/lib/libncursesw.so: file too short) The file certainly exists but is only 32 bytes. I installed from Ubuntu's package manager. I am working on a 64 bit machine (if that helps). Can someone help me fix this? Thanks, Aditya. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/1dc0805f/attachment-0001.htm> ------------------------------ Message: 8 Date: Sat, 10 Mar 2012 12:56:53 +0530 From: Aditya Manthramurthy <aditya....@gmail.com> Subject: Re: [Haskell-beginners] Problem with developing NCurses program To: beginners@haskell.org Message-ID: <CAC_mE94PW3EAbAzZEFBoY7U=0=wf1gnibhm4kogcfbe7m_q...@mail.gmail.com> Content-Type: text/plain; charset="utf-8" It appears that this is a problem related to ghc: https://bugzilla.redhat.com/show_bug.cgi?id=578509 I am using ghc 7.0.3 which comes with the latest Ubuntu (11.10). Would installing the latest ghc release help? On 10 March 2012 12:50, Aditya Manthramurthy <aditya....@gmail.com> wrote: > HI, > > I am learning haskell by writing small programs. In this instance I want > to write a program using the haskell binding of the NCurses library. > > Here is the (rather simple) code: > > import UI.NCurses > > main = do > putStrLn "Hello World" > > > When I try to run it: > > $ runhaskell cursesprog.hs > cursesprog.hs: <command line>: can't load .so/.DLL for: ncursesw > (/usr/lib/libncursesw.so: file too short) > > The file certainly exists but is only 32 bytes. I installed from Ubuntu's > package manager. I am working on a 64 bit machine (if that helps). > > Can someone help me fix this? > > Thanks, > Aditya. > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.haskell.org/pipermail/beginners/attachments/20120310/ab0fe23b/attachment.htm> ------------------------------ _______________________________________________ Beginners mailing list Beginners@haskell.org http://www.haskell.org/mailman/listinfo/beginners End of Beginners Digest, Vol 45, Issue 10 *****************************************