Re: [Haskell-cafe] On to applicative
On 26 August 2010 15:56, michael rice nowg...@yahoo.com wrote: From: http://en.wikibooks.org/wiki/Haskell/Applicative_Functors = import Control.Applicative f :: (a - b - c) fmap :: Functor f = (d - e) - f d - f e fmap f :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) sumsqr :: Int - Int - Int -- my f sumsqr i j = i*i+j*j = The line with the error is the one beginning with fmap f :: ...; you can't provide a variable/parameter on the left hand side of the :: Also, why are you trying to re-define fmap? -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
2010/8/26 michael rice nowg...@yahoo.com From: http://en.wikibooks.org/wiki/Haskell/Applicative_Functors = import Control.Applicative f :: (a - b - c) fmap :: Functor f = (d - e) - f d - f e fmap f :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) sumsqr :: Int - Int - Int -- my f sumsqr i j = i*i+j*j = I'm trying to understand how the above works but... [mich...@localhost ~]$ ghci GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linking ... done. Loading package ffi-1.0 ... linking ... done. Prelude :l bozo.hs [1 of 1] Compiling Main ( bozo.hs, interpreted ) bozo.hs:5:0: Invalid type signature Failed, modules loaded: none. Prelude Hi, The fifth line has the form x y :: ... instead of x :: ... This is not a legal type signature. Furthermore, you can't give fmap two signatures in the same source file. The reason this is given on the page you linked is for demonstration purpose (well, I guess, I haven't read it). Cheers, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
Yeah, I figured as much, but the code is copied right off the referenced page. Michael --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:02 AM On 26 August 2010 15:56, michael rice nowg...@yahoo.com wrote: From: http://en.wikibooks.org/wiki/Haskell/Applicative_Functors = import Control.Applicative f :: (a - b - c) fmap :: Functor f = (d - e) - f d - f e fmap f :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) sumsqr :: Int - Int - Int -- my f sumsqr i j = i*i+j*j = The line with the error is the one beginning with fmap f :: ...; you can't provide a variable/parameter on the left hand side of the :: Also, why are you trying to re-define fmap? -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On 26 August 2010 16:09, michael rice nowg...@yahoo.com wrote: Yeah, I figured as much, but the code is copied right off the referenced page. Because as Vo Minh Thu says, it was there as a demonstration; in this instance they were doing algebraic manipulation of the code and corresponding type signatures. Admittedly, the wording could have been improved... -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
Can you recommend an example that works? Michael --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:13 AM On 26 August 2010 16:09, michael rice nowg...@yahoo.com wrote: Yeah, I figured as much, but the code is copied right off the referenced page. Because as Vo Minh Thu says, it was there as a demonstration; in this instance they were doing algebraic manipulation of the code and corresponding type signatures. Admittedly, the wording could have been improved... -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On 26 August 2010 16:29, michael rice nowg...@yahoo.com wrote: Can you recommend an example that works? An example of what? The definitions of fmap2, etc. on that page look like they're correct. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
OK, fmap2 works, but not fmap3. What am I not understanding? Michael import Control.Applicative -- f :: (a - b - c) -- fmap :: Functor f = (d - e) - f d - f e sumsqr :: Int - Int - Int sumsqr i j = i*i+j*j -- fmap :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) fmap2 f a b = f `fmap` a * b fmap3 f a b c = f `fmap` a * b * c fmap4 f a b c d = f `fmap` a * b * c * d -- fmap2 f a b = f $ a * b -- fmap3 f a b c = f $ a * b * c -- fmap4 f a b c d = f $ a * b * c * d *Main fmap2 sumsqr (Just 3) (Just 4) Just 25 *Main fmap3 sumsqr (Just 3) (Just 4) (Just 5) interactive:1:6: Couldn't match expected type `a2 - b' against inferred type `Int' In the first argument of `fmap3', namely `sumsqr' In the expression: fmap3 sumsqr (Just 3) (Just 4) (Just 5) In the definition of `it': it = fmap3 sumsqr (Just 3) (Just 4) (Just 5) *Main --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:33 AM On 26 August 2010 16:29, michael rice nowg...@yahoo.com wrote: Can you recommend an example that works? An example of what? The definitions of fmap2, etc. on that page look like they're correct. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On 26 August 2010 16:47, michael rice nowg...@yahoo.com wrote: OK, fmap2 works, but not fmap3. What am I not understanding? Michael import Control.Applicative -- f :: (a - b - c) -- fmap :: Functor f = (d - e) - f d - f e sumsqr :: Int - Int - Int sumsqr i j = i*i+j*j -- fmap :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) fmap2 f a b = f `fmap` a * b fmap3 f a b c = f `fmap` a * b * c fmap4 f a b c d = f `fmap` a * b * c * d -- fmap2 f a b = f $ a * b -- fmap3 f a b c = f $ a * b * c -- fmap4 f a b c d = f $ a * b * c * d *Main fmap2 sumsqr (Just 3) (Just 4) Just 25 *Main fmap3 sumsqr (Just 3) (Just 4) (Just 5) interactive:1:6: Couldn't match expected type `a2 - b' against inferred type `Int' In the first argument of `fmap3', namely `sumsqr' In the expression: fmap3 sumsqr (Just 3) (Just 4) (Just 5) In the definition of `it': it = fmap3 sumsqr (Just 3) (Just 4) (Just 5) *Main sumsqr takes three arguments; fmap3 has type: fmap3 :: (a - b - c - d) - Maybe a - Maybe b - Maybe c - Maybe d i.e. the function you pass it needs to take 3 arguments. fmap3 (\ x y z - z * y + z) (Just 1) (Just 2) (Just 3) --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:33 AM On 26 August 2010 16:29, michael rice nowg...@yahoo.com wrote: Can you recommend an example that works? An example of what? The definitions of fmap2, etc. on that page look like they're correct. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
I think it works well :) But sumsqr has type Int - Int - Int, not Int - Int - Int - Int. I.e. it does take only two arguments while fmap3 takes a function of three arguments. 2010/8/26 michael rice nowg...@yahoo.com OK, fmap2 works, but not fmap3. What am I not understanding? Michael import Control.Applicative -- f :: (a - b - c) -- fmap :: Functor f = (d - e) - f d - f e sumsqr :: Int - Int - Int sumsqr i j = i*i+j*j -- fmap :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) fmap2 f a b = f `fmap` a * b fmap3 f a b c = f `fmap` a * b * c fmap4 f a b c d = f `fmap` a * b * c * d -- fmap2 f a b = f $ a * b -- fmap3 f a b c = f $ a * b * c -- fmap4 f a b c d = f $ a * b * c * d *Main fmap2 sumsqr (Just 3) (Just 4) Just 25 *Main fmap3 sumsqr (Just 3) (Just 4) (Just 5) interactive:1:6: Couldn't match expected type `a2 - b' against inferred type `Int' In the first argument of `fmap3', namely `sumsqr' In the expression: fmap3 sumsqr (Just 3) (Just 4) (Just 5) In the definition of `it': it = fmap3 sumsqr (Just 3) (Just 4) (Just 5) *Main --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:33 AM On 26 August 2010 16:29, michael rice nowg...@yahoo.com wrote: Can you recommend an example that works? An example of what? The definitions of fmap2, etc. on that page look like they're correct. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
Hmm... it was my understanding that the example was showing how to *avoid* having to create a lot of functions that do the same thing but have different numbers of arguments. From the Wiki page: Anytime you feel the need to define different higher order functions to accommodate for function-arguments with a different number of arguments, think about how defining a proper instance of Applicative can make your life easier. Not so? Michael --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:50 AM On 26 August 2010 16:47, michael rice nowg...@yahoo.com wrote: OK, fmap2 works, but not fmap3. What am I not understanding? Michael import Control.Applicative -- f :: (a - b - c) -- fmap :: Functor f = (d - e) - f d - f e sumsqr :: Int - Int - Int sumsqr i j = i*i+j*j -- fmap :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) fmap2 f a b = f `fmap` a * b fmap3 f a b c = f `fmap` a * b * c fmap4 f a b c d = f `fmap` a * b * c * d -- fmap2 f a b = f $ a * b -- fmap3 f a b c = f $ a * b * c -- fmap4 f a b c d = f $ a * b * c * d *Main fmap2 sumsqr (Just 3) (Just 4) Just 25 *Main fmap3 sumsqr (Just 3) (Just 4) (Just 5) interactive:1:6: Couldn't match expected type `a2 - b' against inferred type `Int' In the first argument of `fmap3', namely `sumsqr' In the expression: fmap3 sumsqr (Just 3) (Just 4) (Just 5) In the definition of `it': it = fmap3 sumsqr (Just 3) (Just 4) (Just 5) *Main sumsqr takes three arguments; fmap3 has type: fmap3 :: (a - b - c - d) - Maybe a - Maybe b - Maybe c - Maybe d i.e. the function you pass it needs to take 3 arguments. fmap3 (\ x y z - z * y + z) (Just 1) (Just 2) (Just 3) --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:33 AM On 26 August 2010 16:29, michael rice nowg...@yahoo.com wrote: Can you recommend an example that works? An example of what? The definitions of fmap2, etc. on that page look like they're correct. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Re : Re: Re : Error importing
btw, this could be helpful, if you have some time: http://en.wikipedia.org/wiki/Cabal_(software) http://www.haskell.org/cabal/ in there you maay find : http://www.haskell.org/cabal/FAQ.html in which you can see ( hey !): Hidden packages (a)http://www.haskell.org/cabal/FAQ.html#hidden-packages-a What is this hidden package? You're writing your own package and you get: Could not find module `Data.Map': it is a member of package containers-0.1.0.0, which is hidden. Hidden packages (b)http://www.haskell.org/cabal/FAQ.html#hidden-packages-b You're building some other package and you get: Could not find module `Data.Map': it is a member of package containers-0.1.0.0, which is hidden. this is insteresting but maybe too advaced for now, may side track you. however may give you the big picture http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program besides, Howard, leksah is a small audience list, you may find more support on the cafe list, as your question as less leksah specific, but more on the haskell bootstrapping procees Ill copy you here, in case some good sould know some fast track ( btw , do you know about rwh : http://book.realworldhaskell.org/read/ especially http://book.realworldhaskell.org/read/installing-ghc-and-haskell-libraries.html#id688956 ) 2010/8/25 HowardBrazee how...@brazee.net Boy, am I dense. I see two depends lines in Reading.cabal: pkgconfig-depends: build-depends: base -any I uncommented out import qualified Data.Map as M and looked at Lekah's message: src\Main.hs:19:17: Could not find module `Data.Map': It is a member of the hidden package `containers-0.3.0.0'. Perhaps you need to add `containers' to the build-depends in your .cabal file. Use -v to see a list of the files searched for. So I put containers after one of the depends: build-depends: containers base -any Leksah said: Setup: .\Reading.cabal has been changed, please re-configure. = Setup: Reading.cabal:9: Parse of field 'build-depends' failed. = Can't activate package C:\Documents and Settings\brazee\My Documents \Code\Windows\Reading\Reading.cabal: 9: user error (Parse of field 'build-depends' failed.) Can't read package file So I undid that change and did this instead: pkgconfig-depends: containers I got the following: Can't read package file Setup: .\Reading.cabal has been changed, please re-configure. = Configuring Reading-0.0.1... Setup: pkg-config version =0.9.0 is required but it could not be found. = The job now runs with these unused imports. I never found build-depends in my cabal file. I edited this with ultra-edit as I know how to get to it. I'm still clueless about what I did, despite being told by two different people what to do and not being able to follow the directions, but doing trial and error instead. Even after I finished, I don't understand the directions. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
This is indeed the case: if you want to apply your sumsqr function or Ivan's (\ x y z - z * y + z), to some Functor (Maybe in this case), you don't have to redefine them, or even to use fmap2 or fmap3: you just have to use $ and *. E.g.: (\ a b c - a + b + c) $ Just 1 * Just 2 * Just 3 2010/8/26 michael rice nowg...@yahoo.com Hmm... it was my understanding that the example was showing how to *avoid* having to create a lot of functions that do the same thing but have different numbers of arguments. From the Wiki page: Anytime you feel the need to define different higher order functions to accommodate for function-arguments with a different number of arguments, think about how defining a proper instance of Applicative can make your life easier. Not so? Michael --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:50 AM On 26 August 2010 16:47, michael rice nowg...@yahoo.com wrote: OK, fmap2 works, but not fmap3. What am I not understanding? Michael import Control.Applicative -- f :: (a - b - c) -- fmap :: Functor f = (d - e) - f d - f e sumsqr :: Int - Int - Int sumsqr i j = i*i+j*j -- fmap :: Functor f = f a - f (b - c) -- Identify d with a, and e with (b - c) fmap2 f a b = f `fmap` a * b fmap3 f a b c = f `fmap` a * b * c fmap4 f a b c d = f `fmap` a * b * c * d -- fmap2 f a b = f $ a * b -- fmap3 f a b c = f $ a * b * c -- fmap4 f a b c d = f $ a * b * c * d *Main fmap2 sumsqr (Just 3) (Just 4) Just 25 *Main fmap3 sumsqr (Just 3) (Just 4) (Just 5) interactive:1:6: Couldn't match expected type `a2 - b' against inferred type `Int' In the first argument of `fmap3', namely `sumsqr' In the expression: fmap3 sumsqr (Just 3) (Just 4) (Just 5) In the definition of `it': it = fmap3 sumsqr (Just 3) (Just 4) (Just 5) *Main sumsqr takes three arguments; fmap3 has type: fmap3 :: (a - b - c - d) - Maybe a - Maybe b - Maybe c - Maybe d i.e. the function you pass it needs to take 3 arguments. fmap3 (\ x y z - z * y + z) (Just 1) (Just 2) (Just 3) --- On Thu, 8/26/10, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: From: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:33 AM On 26 August 2010 16:29, michael rice nowg...@yahoo.com wrote: Can you recommend an example that works? An example of what? The definitions of fmap2, etc. on that page look like they're correct. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On 26 Aug 2010, at 08:01, michael rice wrote: Hmm... it was my understanding that the example was showing how to *avoid* having to create a lot of functions that do the same thing but have different numbers of arguments. From the Wiki page: Anytime you feel the need to define different higher order functions to accommodate for function-arguments with a different number of arguments, think about how defining a proper instance of Applicative can make your life easier. Not so? Very much so – instead of defining liftA2, liftA3 etc like this, just use pure to get things into the applicative, and write * instead of ' ' to apply applicatives and you're done. Don't write liftA3 sumsq (Just 3) (Just 4) (Just 5) Write (pure sumsq) * (pure 3) * (pure 4) * (pure 5) or you can get rid of that first pure with a quick fmap: sumsq $ (pure 3) * (pure 4) * (pure 5) Bob___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?
Daniel Fischer wrote: John Lato wrote: Heinrich Apfelmus wrote: Do you have an example where you want chunking instead of single character access? I am unable to think of any examples where you want chunking for any reason other than efficiency. For many hashing or de/encryption algorithms, chunking is more natural than single-character access. Even when the chunk lengths are unpredictable? After all, unlike with fread in C, you can't request the next chunk to have a certain length with Iteratees. Regards, Heinrich Apfelmus -- http://apfelmus.nfshost.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
A lot of stuff to get one's head around. Was aware of liftM2, liftM3, etc., but not liftA2, liftA3, etc. So, the statement was true, but not the way that was shown in the example, i.e., with fmap2, fmap3, etc., which required different functions for each of the fmaps. Thanks. Appreciate the patience. Michael --- On Thu, 8/26/10, Thomas Davie tom.da...@gmail.com wrote: From: Thomas Davie tom.da...@gmail.com Subject: Re: [Haskell-cafe] On to applicative To: michael rice nowg...@yahoo.com Cc: Ivan Lazar Miljenovic ivan.miljeno...@gmail.com, haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 3:10 AM On 26 Aug 2010, at 08:01, michael rice wrote: Hmm... it was my understanding that the example was showing how to *avoid* having to create a lot of functions that do the same thing but have different numbers of arguments. From the Wiki page: Anytime you feel the need to define different higher order functions to accommodate for function-arguments with a different number of arguments, think about how defining a proper instance of Applicative can make your life easier. Not so? Very much so – instead of defining liftA2, liftA3 etc like this, just use pure to get things into the applicative, and write * instead of ' ' to apply applicatives and you're done. Don't writeliftA3 sumsq (Just 3) (Just 4) (Just 5) Write(pure sumsq) * (pure 3) * (pure 4) * (pure 5) or you can get rid of that first pure with a quick fmap:sumsq $ (pure 3) * (pure 4) * (pure 5) Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On Aug 26, 2010, at 12:34 AM, michael rice wrote: A lot of stuff to get one's head around. Was aware of liftM2, liftM3, etc., but not liftA2, liftA3, etc. liftM and liftA are essentially equivalent (and are both essentially equivalent to fmap) Same for the liftAn = liftMn functions (where n is an integer). Applicative functors are more general than monads, so it makes sense for them to have their own functions. It is a matter of history that liftM was defined before liftA. So, the statement was true, but not the way that was shown in the example, i.e., with fmap2, fmap3, etc., which required different functions for each of the fmaps. Strictly speaking, fmap will work with a function in more than one argument, as long as it is properly typed. This is what makes applicative functors work. Consider that a function f :: a - b - c also has the type f :: a - (b - c). If you feed it an a, (resulting in a value of the form f a), you get a function g :: (b - c). In other words, every function is a function in one argument. Some functions just happen to map to other functions. $ is flip fmap. f $ functor = fmap f functor Consider what happens if f :: a - b. (f $ functor) means pull an a out of the functor, apply f, and return a functor over some b. That is to say, lift f into the functor and apply it. Now consider what happens if f :: a - (b - c). By analogy, this means pull an a out of the functor object, apply f, and return a functor object (f g) :: f (b - c) (In other words, a functor object that contains a function g :: b - c). In order to get a c value out of this, you need to apply g to something. But note that we're not just dealing with g. It is in the functor already, and so doesn't need lifting. So some smart guy wrote a function called * :: (Functor f) = f (b - c) - f b - f c that does just that. This is one of the defining functions for an applicative functor. (And part of the reason for the name. If the functor contains a function, you can apply the functor to properly typed functor objects.) The other function is pure :: (a - b) - f (a - b). It takes a function and lifts it into the functor, without applying it to anything. In other words, given an f :: a - b, pure f * functor = f $ functor If f has a bigger type (say, a - b - c - d), you can do things like: f $ functor_on_a * functor_on_b * functor_on_c Every monad is an applicative functor. If we have a monad action m_f :: m (a - b), and another one m_a :: (m a), we can get a monad action in type (m b) by pulling the function f :: a - b out of the first one and applying it to the b in the second one: m_f = (\f - liftM f m_a) or... m_f = (flip liftM) m_a In fact, there is a function called ap :: m (a - b) - m a - m b which does just that, and is essentially equivalent to *. Of course, running return on a function f is equivalent to running pure on f. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On Aug 26, 2010, at 1:29 AM, Alexander Solla wrote: The other function is pure :: (a - b) - f (a - b). It takes a function and lifts it into the functor, without applying it to anything. In other words, given an f :: a - b, My mistake, though if you got the rest of it, it should come as no surprise that pure :: a - f a and is essentially equivalent to a monad's return. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] non-blocking recv from UDP socket
Hi, Is is possible to get Network.Socket.ByteString.recv to be non-blocking (i.e. return directly even if no data is available) ? I have tried ti use setSocketOption sock NoDelay 1 but then I get the following error: setSocketOption: unsupported operation (Protocol not available) Here is the code if it may help (I'm on linux btw). sock - socket AF_INET Datagram 17 -- 17 is IPPROTO_UDP addr - inet_addr 127.0.0.1 bindSocket sock (SockAddrInet 44004 addr) setSocketOption sock NoDelay 1 -- -- doesn't seem to work addr - inet_addr 127.0.0.1 forever $ do sent - sendTo sock hello (SockAddrInet 44005 addr) dat - recv sock 5 -- -- I'd like it to be non-blocking B.putStrLn dat threadDelay 100 -- 1 second Thanks, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On Thu, Aug 26, 2010 at 01:29:16AM -0700, Alexander Solla wrote: $ is flip fmap. f $ functor = fmap f functor Just a quick correction: $ is fmap, not flip fmap. -Brent ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] non-blocking recv from UDP socket
Hi Thu, On Thu, Aug 26, 2010 at 11:13 AM, Vo Minh Thu not...@gmail.com wrote: Is is possible to get Network.Socket.ByteString.recv to be non-blocking (i.e. return directly even if no data is available) ? Unfortunately not. I have tried ti use setSocketOption sock NoDelay 1 but then I get the following error: setSocketOption: unsupported operation (Protocol not available) Sockets are already set to be non-blocking and the blocking semantics are implemented on top of non-blocking sockets using e.g. the select system call. It's not the recv syscall that blocks but the I/O manager who blocks you're thread because recv returned WOULD_BLOCK. The I/O manager calls threadWaitRead upon receiving this error. threadWaitRead puts the thread to sleep until the socket is readable (as indicated by select). We could perhaps implement a truly non-blocking API. Cheers, Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] non-blocking recv from UDP socket
2010/8/26 Johan Tibell johan.tib...@gmail.com: Hi Thu, On Thu, Aug 26, 2010 at 11:13 AM, Vo Minh Thu not...@gmail.com wrote: Is is possible to get Network.Socket.ByteString.recv to be non-blocking (i.e. return directly even if no data is available) ? Unfortunately not. I have tried ti use setSocketOption sock NoDelay 1 but then I get the following error: setSocketOption: unsupported operation (Protocol not available) Sockets are already set to be non-blocking and the blocking semantics are implemented on top of non-blocking sockets using e.g. the select system call. It's not the recv syscall that blocks but the I/O manager who blocks you're thread because recv returned WOULD_BLOCK. The I/O manager calls threadWaitRead upon receiving this error. threadWaitRead puts the thread to sleep until the socket is readable (as indicated by select). Ok, that explains also why using fcntl directly on the fd didn't work either. So, I think I will go the FFI road and create my socket the way I want. Do you see another way? We could perhaps implement a truly non-blocking API. If it is widely useful, I guess it would be great. I don't mind writing some C and using the FFI though. Thanks for your answer, Thu ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] non-blocking recv from UDP socket
On Thu, Aug 26, 2010 at 1:08 PM, Vo Minh Thu not...@gmail.com wrote: Ok, that explains also why using fcntl directly on the fd didn't work either. So, I think I will go the FFI road and create my socket the way I want. Do you see another way? Not if you want a solution right now. You can still use Network.Socket.Internal to get hold of the file descriptor and that way your new function will work with the old Socket type. If it is widely useful, I guess it would be great. I don't mind writing some C and using the FFI though. OK. I don't quite have time to look into it right now. If someone could suggest an API (and then implement it) I would be happy to review the patches. -- Johan ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Hackage on Linux
On 22/08/2010 11:41, Andrew Coppin wrote: Ivan Lazar Miljenovic wrote: Hackage has limited support for distro maintainers to state which packages are available on the distribution. Last I checked, it required distro maintainers to keep a text file somewhere up to date. Note that not all distributions bother. Yeah, I figured. I don't see any Debian or OpenSUSE anywhere, and I know they do have at least a few pre-built binary packages out there. It looks as if it's automated for Arch, however. Either that or somebody is spending an absurd amount of time keeping it manually up to date. (in particular none of us involved with packaging Haskell packages for Gentoo can be bothered; we're slowly cutting back into only keeping packages that will actually be used rather than all and sundry) Well, I guess you either manually select which packages to convert, or you have an automated system convert everything in sight. This whole observation came about because I noticed that some (but not all) of my own packages have ended up on Arch, despite being of almost no use to anybody. I was just curious as to how that happened. As for why using your distro package manager for Haskell packages is preferable: http://ivanmiljenovic.wordpress.com/2010/03/15/repeat-after-me-cabal-is-not-a-package-manager/ Right. So Cabal isn't a package manager because it only manages Haskell packages? Not sure I agree with that definition. (It also has a laundry list of problems that can and should be fixed, but won't be.) I actually spent quite a while trying to figure out what the purpose of Cabal *is*. It's not like it's hard to download a bunch of Haskell source code and utter ghc --make Foo. So why do we even need Cabal in the first place? The answer, as far as I can tell, is that registering a library manually is so excruciatingly hard that we actually need a tool to automate the process. (Obviously when I first started using Haskell, I was mainly interested in writing runnable programs, not libraries.) Cabal can also run Haddock for you, which is quite hard. But it wasn't until cabal-install came along that I even realised that Cabal could track and resolve dependencies. (The fact that it doesn't track installed executables is news to me.) If nothing else, I think that what Cabal is should be documented much more clearly. It took me a hell of a long time to figure this out. Now, you say it's preferable to use the native package manager where possible. I've got one word for you: Windows. You know, the most popular OS on the market? The one installed on 98% of all computers world-wide? Guess what: no native package manager. Actually, we have tools that automatically convert Cabal packages to Debian packages or RPMs or whatever. I think there could be some milage in a tool that builds Windows installers. (The problem, of course, is that you have to be able to *build* the library on Windows first!) You would of course then have all kinds of fun and games with dependency tracking... If you look at the original Cabal design document[1], you'll see that one of the goals of Cabal was to be the glue that lets you convert an arbitrary Haskell library into a native package for a variety of systems - including MSIs on Windows. Indeed, I must admit when we were designing Cabal I thought that native packages would be the most common way that people would install Cabal packages, specifically because many systems already have a good package manager, and trying to bypass the system package manager would be a fundamental mistake. It turned out that cabal-install would be a lot more useful than I imagined, but the two systems are complementary: native packages are for installing globally, and cabal-install is for installing packages in your home directory. Even on systems without a package manager (i.e. Windows), it would make more sense when installing a package globally to build an MSI first, so that the system can track the installation and let you uninstall it later. There was a prototype Windows Installer builder for Cabal, cabal2wix [2] but I think the project is currently dormant. [1] http://www.haskell.org/cabal/proposal/ [2] http://www.haskell.org/pipermail/cabal-devel/2007-August/000740.html Cheers, Simon ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
marlowsd: If you look at the original Cabal design document[1], you'll see that one of the goals of Cabal was to be the glue that lets you convert an arbitrary Haskell library into a native package for a variety of systems - including MSIs on Windows. Indeed, I must admit when we were designing Cabal I thought that native packages would be the most common way that people would install Cabal packages, specifically because many systems already have a good package manager, and trying to bypass the system package manager would be a fundamental mistake. It turned out that cabal-install would be a lot more useful than I imagined, but the two systems are complementary: native packages are for installing globally, and cabal-install is for installing packages in your home directory. We also didn't know that Hackage would get so big, so quickly. So there's three levels of packages now: 1. absolutely vital: HP (now on every system) 2. native packaging of useful Haskell apps and libs (many on Debian, Arch, Gentoo, few elsewhere) 3. cabal-install: everything else, works everywhere. And it looks like many distros are learning towards just providing 1. natively. Those with more automation (Debian, Arch) do 2. as well, though it is less useful than we thought now that cabal-install is relatively stable. A new trend are tools like 'bauerbill' on Arch, which has a --hackage flag, that converts hackage to native packages on the fly. That's like teaching apt to grok hackage. It's interesting how its all sorting out. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Re : Re: Re : Error importing
On Thursday 26 August 2010 09:04:23, Luc TAESCH wrote: and looked at Lekah's message: src\Main.hs:19:17: Could not find module `Data.Map': It is a member of the hidden package `containers-0.3.0.0'. Perhaps you need to add `containers' to the build-depends in your .cabal file. Use -v to see a list of the files searched for. So I put containers after one of the depends: build-depends: containers base -any build-depends has to be a comma-separated list, iirc, try build-depends: containers = 0.3 0.4, base -any Although, I recommend also putting version constraints on base. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Fwd: Semantics of iteratees, enumerators, enumeratees?
On Thursday 26 August 2010 09:33:30, Heinrich Apfelmus wrote: Daniel Fischer wrote: John Lato wrote: Heinrich Apfelmus wrote: Do you have an example where you want chunking instead of single character access? I am unable to think of any examples where you want chunking for any reason other than efficiency. For many hashing or de/encryption algorithms, chunking is more natural than single-character access. Even when the chunk lengths are unpredictable? After all, unlike with fread in C, you can't request the next chunk to have a certain length with Iteratees. Well, I just gave an example where one would want chunking for reasons other than performance. That iteratees don't provide the desired functionality is a different matter. For performance reasons, one would still be likely to want the I/O to happen in larger chunks than the processing, so it's kind of moot. Cheers, Daniel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
RE: [Haskell-cafe] foreign function interface Invalid type signature
The HEAD now does FFI by default (Haskell 2010) so you would not have tripped over this. But even if you use the -XHaskell98 flag to recover Haskell-98 mode, you get this error: Foo.hs:9:1: Invalid type signature: foreign export ccall foo :: CInt - CInt Perhaps you meant to use -XForeignFunctionInterface? Which would have been more helpful for you. Simon | -Original Message- | From: haskell-cafe-boun...@haskell.org [mailto:haskell-cafe- | boun...@haskell.org] On Behalf Of Ivan Lazar Miljenovic | Sent: 26 August 2010 01:48 | To: Ken Takusagawa | Cc: Haskell Cafe | Subject: Re: [Haskell-cafe] foreign function interface Invalid type | signature | | On 26 August 2010 10:41, Ken Takusagawa ken.takusagaw...@gmail.com wrote: | What am I doing wrong? | | module Ffi2 where | { | import Foreign.C.Types; | | foo :: CInt - CInt; | foo x = x; | | foreign export ccall foo :: CInt - CInt; | | } | | Did you enable the | | | $ ghc -c Ffi2.hs | | Ffi2.hs:8:0: Invalid type signature | | You need to call it with -XForeignFunctionInterface to enable FFI methinks. | | | -- | Ivan Lazar Miljenovic | ivan.miljeno...@gmail.com | IvanMiljenovic.wordpress.com | ___ | Haskell-Cafe mailing list | Haskell-Cafe@haskell.org | http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
On Thu, Aug 26, 2010 at 5:02 AM, Don Stewart d...@galois.com wrote: marlowsd: If you look at the original Cabal design document[1], you'll see that one of the goals of Cabal was to be the glue that lets you convert an arbitrary Haskell library into a native package for a variety of systems - including MSIs on Windows. Indeed, I must admit when we were designing Cabal I thought that native packages would be the most common way that people would install Cabal packages, specifically because many systems already have a good package manager, and trying to bypass the system package manager would be a fundamental mistake. It turned out that cabal-install would be a lot more useful than I imagined, but the two systems are complementary: native packages are for installing globally, and cabal-install is for installing packages in your home directory. We also didn't know that Hackage would get so big, so quickly. So there's three levels of packages now: 1. absolutely vital: HP (now on every system) 2. native packaging of useful Haskell apps and libs (many on Debian, Arch, Gentoo, few elsewhere) 3. cabal-install: everything else, works everywhere. And it looks like many distros are learning towards just providing 1. natively. Those with more automation (Debian, Arch) do 2. as well, though it is less useful than we thought now that cabal-install is relatively stable. A new trend are tools like 'bauerbill' on Arch, which has a --hackage flag, that converts hackage to native packages on the fly. That's like teaching apt to grok hackage. It's interesting how its all sorting out. -- Don ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Library packages are only interesting to me when it comes to application deployment. Things are greatly simplified when you DO NOT have shared libraries to contend with because the only person tracking dependencies is the developer. Go, for example, has no shared libraries, and the runtime fits in every binary. It does not even depend on libc. Go binaries call the system call interface of the kernel, and the net result is that I get to test my go code, deploy it, and not worry about the state of deployed go environments quite so much as I do in the presence of shared libraries. As such I think cabal-install is excellent in that it installs in the developer's home directory, because that's all I need in other environments as well. It's quite practical. People are obsessed with shared library support but I can not for the life of me figure out why. Dave ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Crypto-API is stabilizing
class (Binary p, Serialize p) = AsymCipher p where generateKeypair :: RandomGen g = g - BitLength - Maybe ((p,p),g) encryptAsym :: p - B.ByteString - B.ByteString decryptAsym :: p - B.ByteString - B.ByteString asymKeyLength :: p - BitLength Regarding AsymCipher: Some algorithms do not lend themselves to encryption/decryption or have special properties which differentiate their use in enc/dec an signing/verifying. I propose the following two additions for the class: signAsym :: p - B.ByteString - B.ByteString verifyAsym :: p - B.ByteString - Bool This way algorithms can leave parts undefined which do not apply to them or hide their different behaviour. I am strongly against classes for which we already know instanes will need a good deal of undefined routines. Another possibility would be a split of AsymCipher into AsymCipherEnc (which is just like the old AsymCipher) and AsymCipherSig for Signatures. Textbook-RSA is special, since it can implement both classes with a minimum of effort, but a clean separation would be nice (and there wouldn't be that many undefined functions). Perhaps even zero undefined functions. I like this suggestion, though I'm not aware of any haskell implementations that will take advantage of a Signature class yet. Unless someone can point to something like a DSA or ECDSA on hackage I'll probably release crypto-api 0.1 without this class (it would still likely appear in a later version after further consideration). Another thing: A central interface to get the output of a PRNG would be nice, preferably not constrained to Int like RandomGen. Designing a random interface that provides something as high a level as monad random, is easy enough to make instances for (like RandomGen) and is feature rich enough to allow reseeding, additional entropy input, personalization, and failure is a non-trivial design task. Having ran into the dilemma of how to provide a reasonable high-level interface for DRBG, I agree with your statement but don't know how a solution would look. FYI, BOS had a similar suggestion (on the blog) of moving away from RandomGen but I'm not clear on what I'd move toward. Cheers, Thomas ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
David Leimbach wrote: It's quite practical. People are obsessed with shared library support but I can not for the life of me figure out why. Maybe because a simple Hello World program in Haskell becomes about 2MB when compiled? (The equivilent C program ends up being 15KB or something, which is just a tad smaller.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
It does make a difference in certain cases. For a 2MB binary to be trivial it assumes that (1) you are in a developed country (2) you are using a landline internet connection and not going through your cell-phone company, although this gap is closing fast. I feel this India whenever I visit India. Most people buy into a data option through their cell phones and the available bandwidth is about an order of magnitude *below* DSL. So that's one case where 15KB vs. 2MB is a big deal. -deech On Thu, Aug 26, 2010 at 10:50 AM, Andrew Coppin andrewcop...@btinternet.com wrote: David Leimbach wrote: It's quite practical. People are obsessed with shared library support but I can not for the life of me figure out why. Maybe because a simple Hello World program in Haskell becomes about 2MB when compiled? (The equivilent C program ends up being 15KB or something, which is just a tad smaller.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
Hi Alexander, Didn't get to sleep till 4 AM and it took me a while to go though your post. So far... --- On Thu, 8/26/10, Alexander Solla a...@2piix.com wrote: From: Alexander Solla a...@2piix.com Subject: Re: [Haskell-cafe] On to applicative To: Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 4:29 AM On Aug 26, 2010, at 12:34 AM, michael rice wrote: A lot of stuff to get one's head around. Was aware of liftM2, liftM3, etc., but not liftA2, liftA3, etc. liftM and liftA are essentially equivalent (and are both essentially equivalent to fmap) Same for the liftAn = liftMn functions (where n is an integer). Applicative functors are more general than monads, so it makes sense for them to have their own functions. It is a matter of history that liftM was defined before liftA. So, the statement was true, but not the way that was shown in the example, i.e., with fmap2, fmap3, etc., which required different functions for each of the fmaps. Strictly speaking, fmap will work with a function in more than one argument, as long as it is properly typed. This is what makes applicative functors work. Consider that a function f :: a - b - c also has the type f :: a - (b - c). If you feed it an a, (resulting in a value of the form f a), you get a function g :: (b - c). In other words, every function is a function in one argument. ### Knew that fact, but it needed to be dusted off. Some functions just happen to map to other functions. $ is flip fmap. f $ functor = fmap f functor Brent Yorgey's post noted. map to? Take as arguments? Consider what happens if f :: a - b. (f $ functor) means pull an a out of the functor, apply f, and return a functor over some b. That is to say, lift f into the functor and apply it. OK. Prelude Control.Applicative let double x = x+x Prelude Control.Applicative (double $ (Just 7)) Just 14 Now consider what happens if f :: a - (b - c). By analogy, this means pull an a out of the functor object, apply f, and return a functor object (f g) :: f (b - c) (In other words, a functor object that contains a function g :: b - c). In order to get a c value out of this, you need to apply g to something. But note that we're not just dealing with g. It is in the functor already, and so doesn't need lifting. So some smart guy wrote a function called * :: (Functor f) = f (b - c) - f b - f c Prelude Control.Applicative let plus x y = x+y Prelude Control.Applicative let f = (plus $ (Just 3)) Prelude Control.Applicative f (Just 4) interactive:1:0: Couldn't match expected type `Maybe t1 - t' against inferred type `Maybe (Integer - Integer)' In the expression: f (Just 4) In the definition of `it': it = f (Just 4) Prelude Control.Applicative f * (Just 4) Just 7 OK. Partial evaluation with functors? that does just that. This is one of the defining functions for an applicative functor. (And part of the reason for the name. If the functor contains a function, you can apply the functor to properly typed functor objects.) The other function is pure :: (a - b) - f (a - b). It takes a function and lifts it into the functor, without applying it to anything. In other words, given an f :: a - b, pure f * functor = f $ functor Prelude Control.Applicative pure double * (Just 5) Just 10 Not so, the f got applied or where did we get the 10? Not sure, is this the mistake you point out in your second post? Two ways of doing the same thing? 1) Prelude Control.Applicative (double $ (Just 7)) Just 14 2) Prelude Control.Applicative pure double * (Just 7) Just 14 Still looking at rest of your post. If f has a bigger type (say, a - b - c - d), you can do things like: f $ functor_on_a * functor_on_b * functor_on_c Every monad is an applicative functor. If we have a monad action m_f :: m (a - b), and another one m_a :: (m a), we can get a monad action in type (m b) by pulling the function f :: a - b out of the first one and applying it to the b in the second one: m_f = (\f - liftM f m_a) or... m_f = (flip liftM) m_a In fact, there is a function called ap :: m (a - b) - m a - m b which does just that, and is essentially equivalent to *. Of course, running return on a function f is equivalent to running pure on f. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] non-blocking recv from UDP socket
Quoth Vo Minh Thu not...@gmail.com, ... Ok, that explains also why using fcntl directly on the fd didn't work either. So, I think I will go the FFI road and create my socket the way I want. I have been doing this with TCP STREAM sockets for some time, for similar reasons and others, and as you surmised, it has worked fine. Donn Cave, d...@avvanta.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] non-blocking recv from UDP socket
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 8/26/10 05:13 , Vo Minh Thu wrote: Is is possible to get Network.Socket.ByteString.recv to be non-blocking (i.e. return directly even if no data is available) ? What are you really trying to do? The Haskelly solution to this is to use threads; let the thread reading the socket block and the main thread synchronize with it somehow. (Haskell threads are very inexpensive; don't be afraid of them.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx2mn4ACgkQIn7hlCsL25U2fQCgjHzzO3f61z7GeyVZfJIaet7k vE4An1CaiqTke6BdpuvYsg5U0d+n3Ig7 =QcGa -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] non-blocking recv from UDP socket
2010/8/26 Brandon S Allbery KF8NH allb...@ece.cmu.edu: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 8/26/10 05:13 , Vo Minh Thu wrote: Is is possible to get Network.Socket.ByteString.recv to be non-blocking (i.e. return directly even if no data is available) ? What are you really trying to do? The Haskelly solution to this is to use threads; let the thread reading the socket block and the main thread synchronize with it somehow. (Haskell threads are very inexpensive; don't be afraid of them.) Well, I have written the FFI and it works fine. What I'm doing is the networking part of a game loop following some nice ressource[0]. I'll wait a bit to have more experience with the code before changing how it is designed (e.g. using light threads). Fast paced 3D action games (and physics) networking seems quite involved. At first sight for instance, it seems easier to have an 'update' function for the networking code to detect timeout than to have it implemented on top of a waiting thread. (Such an update function is quite pervasive in a (imperative) game loop). Also the same socket is used both to read and write, so this would need additional synchronization. But thanks for the suggestion, it might be a good one later on. Cheers, Thu [0] http://gafferongames.wordpress.com/networking-for-game-programmers/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Ordering TypeRep from Data.Typeable.
I think, that TypeRep type from Data.Typeable needs Ord class instance. It is unnecessary, but is handy when needed. My use case follows. I try to create graph whose node and arc labels are differently typed. So I can add Int node, Float node and link them by Conversion arc. Right now I am quite good with GADTs that hide values of different types. But when I thinking about querying that structure, I start to want ordered TypeRep. I then can collect different arcs and nodes into different sets and speed up query processing dramatically. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Chez What
On Mon, Aug 9, 2010 at 11:47 AM, Jeff Rubard jeffrub...@gmail.com wrote: Haskell CURRY? Curried potatoes? The lambda calculus? Historical actuality? SI! LISP? John McCarthy? Etc ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 8/26/10 10:23 , David Leimbach wrote: Go, for example, has no shared libraries, and the runtime fits in every binary. It does not even depend on libc. Go binaries call the system call interface of the kernel, and the net result is that I get to test my go code, deploy it, and not worry about the state of deployed go environments quite so much as I do in the presence of shared libraries. Um. That's a really good way to have all your programs stop working when the Linux kernel interface changes yet again (ABIs? We don't need no steenking ABIs! --- see in /usr/src/linux/Documentation). Solaris is similar; the only approved interface is via libc and you must link to it shared if you want your program to work across versions/releases. (Which is the reason shared library support is important. I personally like my programs to keep working.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx2rmMACgkQIn7hlCsL25XmjACgmWne8rR0EYeeHIBZvp2gywLp KDMAoKLGedOj5Dy2GXBo+NLcbCGemhS8 =XBmS -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
On Aug 26, 2010, at 9:27 AM, michael rice wrote: Some functions just happen to map to other functions. $ is flip fmap. f $ functor = fmap f functor Brent Yorgey's post noted. map to? Take as arguments? maps to as in outputs. pure f * functor = f $ functor Prelude Control.Applicative pure double * (Just 5) Just 10 Not so, the f got applied or where did we get the 10? Not sure, is this the mistake you point out in your second post? double is getting applied in that expression, but it isn't because of pure. The * operator is pulling double out of pure double (which equals Just double in this case), and applying it to Just 5. My correction was to point out that pure's type is more general than I had said. Instead of pure :: (a - b) - f (a - b), it is pure :: a - f a -- which includes (a - b) - f (a - b) as a special case. In fact, pure and return are essentially equivalent in form. So you could write out your verification case as (pure double * pure 5) :: Just Int to further decouple your code from the particular functor you're working with. (You need the type annotation to run it in GHCi) Two ways of doing the same thing? 1) Prelude Control.Applicative (double $ (Just 7)) Just 14 2) Prelude Control.Applicative pure double * (Just 7) Just 14 Indeed. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
On Thu, Aug 26, 2010 at 11:11 AM, Brandon S Allbery KF8NH allb...@ece.cmu.edu wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 8/26/10 10:23 , David Leimbach wrote: Go, for example, has no shared libraries, and the runtime fits in every binary. It does not even depend on libc. Go binaries call the system call interface of the kernel, and the net result is that I get to test my go code, deploy it, and not worry about the state of deployed go environments quite so much as I do in the presence of shared libraries. Um. That's a really good way to have all your programs stop working when the Linux kernel interface changes yet again (ABIs? We don't need no steenking ABIs! --- see in /usr/src/linux/Documentation). Solaris is similar; the only approved interface is via libc and you must link to it shared if you want your program to work across versions/releases. (Which is the reason shared library support is important. I personally like my programs to keep working.) So you have to keep the runtime as up to date as glibc? Sounds ok :-). Also, I don't know anyone that supports people updating kernels in linux in any sort of commercial setting for the very reason you just gave. Sounds like asking for trouble. In my experience, a kernel upgrade is taken pretty seriously, and not done without very good reason. Look at CentOS, it's on a pretty old kernel most of the time, because people in enterprise situations prefer stability over bleeding edge features. Dave - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx2rmMACgkQIn7hlCsL25XmjACgmWne8rR0EYeeHIBZvp2gywLp KDMAoKLGedOj5Dy2GXBo+NLcbCGemhS8 =XBmS -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] On to applicative
When I began looking into applicative, I googled haskell applicative and grabbed the first one on the list, the wikipage. I think a better choice would have been the Learn You a Haskell section on functors/applicative, the second one on the list. I'm going to spend some time there but will no doubt be back before long with another question. Thanks all, Michael --- On Thu, 8/26/10, Alexander Solla a...@2piix.com wrote: From: Alexander Solla a...@2piix.com Subject: Re: [Haskell-cafe] On to applicative To: Cc: haskell-cafe Cafe haskell-cafe@haskell.org Date: Thursday, August 26, 2010, 2:15 PM On Aug 26, 2010, at 9:27 AM, michael rice wrote: Some functions just happen to map to other functions. $ is flip fmap. f $ functor = fmap f functor Brent Yorgey's post noted. map to? Take as arguments? maps to as in outputs. pure f * functor = f $ functor Prelude Control.Applicative pure double * (Just 5) Just 10 Not so, the f got applied or where did we get the 10? Not sure, is this the mistake you point out in your second post? double is getting applied in that expression, but it isn't because of pure. The * operator is pulling double out of pure double (which equals Just double in this case), and applying it to Just 5. My correction was to point out that pure's type is more general than I had said. Instead of pure :: (a - b) - f (a - b), it is pure :: a - f a -- which includes (a - b) - f (a - b) as a special case. In fact, pure and return are essentially equivalent in form. So you could write out your verification case as (pure double * pure 5) :: Just Int to further decouple your code from the particular functor you're working with. (You need the type annotation to run it in GHCi) Two ways of doing the same thing? 1) Prelude Control.Applicative (double $ (Just 7)) Just 14 2) Prelude Control.Applicative pure double * (Just 7) Just 14 Indeed.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Warning: Module `Prelude' is deprecated:
So lately when I use cabal to install something get Text/CSV.hs:1:0: Warning: Module `Prelude' is deprecated: You are using the old package `base' version 3.x. Future GHC versions will not support base version 3.x. You should update your code to use the new base version 4.x. how do I implement cabal's advice? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Warning: Module `Prelude' is deprecated:
On 27 August 2010 10:17, Michael Litchard mich...@schmong.org wrote: So lately when I use cabal to install something get Text/CSV.hs:1:0: Warning: Module `Prelude' is deprecated: You are using the old package `base' version 3.x. Future GHC versions will not support base version 3.x. You should update your code to use the new base version 4.x. how do I implement cabal's advice? Tell upstream to fix their package to use base-4 rather than base-3. -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Warning: Module `Prelude' is deprecated:
As said, this is an issue with the package maintainer who explicitly used base 3.0 as a dependancy I believe that base 3 is gonna be killed in ghc 6.14 iirc On 27/08/2010 10:17 AM, Michael Litchard mich...@schmong.org wrote: So lately when I use cabal to install something get Text/CSV.hs:1:0: Warning: Module `Prelude' is deprecated: You are using the old package `base' version 3.x. Future GHC versions will not support base version 3.x. You should update your code to use the new base version 4.x. how do I implement cabal's advice? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Warning: Module `Prelude' is deprecated:
On 27 August 2010 11:42, Mathew de Detrich dete...@gmail.com wrote: As said, this is an issue with the package maintainer who explicitly used base 3.0 as a dependancy Or they have no upper bound on the version of base in their .cabal file, so cabal-install tries to be clever and defaults to base-3 to be safe (from when base-4 was introduced and many packages wouldn't build with it). Nowadays, is there any reason why we need to consider base-3 compatibility any more? Is it viable to just use base-4 and not bother with extensible-exceptions as a compatibility layer? -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Warning: Module `Prelude' is deprecated:
On Thu, Aug 26, 2010 at 6:45 PM, Ivan Lazar Miljenovic ivan.miljeno...@gmail.com wrote: On 27 August 2010 11:42, Mathew de Detrich dete...@gmail.com wrote: As said, this is an issue with the package maintainer who explicitly used base 3.0 as a dependancy Or they have no upper bound on the version of base in their .cabal file, so cabal-install tries to be clever and defaults to base-3 to be safe (from when base-4 was introduced and many packages wouldn't build with it). Cabal-install further has a bug here where --constraint=base=4 will have no effect. Instead you have to say you prefer base 4. So, cabal install --preference=base=4. I don't understand why preferences override constraints, but that's the way it works for parsec and base (most other packages are not handled in this buggy way). Nowadays, is there any reason why we need to consider base-3 compatibility any more? Is it viable to just use base-4 and not bother with extensible-exceptions as a compatibility layer? I've added preference: base = 4, in my global cabal-install config and I haven't had a single issue since. I HIGHLY recommend everyone to do this. I think the way cabal-install ignores constraints on base and parsec to be a rather serious bug in the hackage infrastructure. Yes, I know about the historic reason that prompted this bug to be added to cabal-install. Still, I think cabal-install should either do what the user requests, or fail with an explanation. People should be forced to fix their packages. The current behavior of ignoring constraints against base has cost me more time than it has saved, I'm sure. Note: cabal install foo --constraint=base = 4 base 5, might also work, specifically adding an upper bound on the command line. Once I found the preference trick I never went back to try it. Jason ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Warning: Module `Prelude' is deprecated:
On 27 August 2010 12:01, Jason Dagit da...@codersbase.com wrote: I've added preference: base = 4, in my global cabal-install config and I haven't had a single issue since. I HIGHLY recommend everyone to do this. Ooohhh, didn't know you could put preferences and constraints in your config file for cabal-install... -- Ivan Lazar Miljenovic ivan.miljeno...@gmail.com IvanMiljenovic.wordpress.com ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
On Aug 27, 2010, at 6:11 AM, Brandon S Allbery KF8NH wrote: Um. That's a really good way to have all your programs stop working when the Linux kernel interface changes yet again (ABIs? We don't need no steenking ABIs! --- see in /usr/src/linux/Documentation). Solaris is similar; the only approved interface is via libc and you must link to it shared if you want your program to work across versions/releases. Yeah, right. So here I am running SunOS 5.10 Generic January 2005 and the version/release has changed incompatibly just *how* often? That's on a SPARC. On the Mac I have OpenSolaris, and guess how often new releases have broken things on that? This little helpfulness from Sun (can't blame Oracle for this one, much as I'd like to) broke profiling and has never ever gained me personally anything. If there _were_ a new release I'd have to rebuild everything anyway, A *P* I changes have been more common than A *B* I ones. Maybe Linux is different. One thing is NOT different, and that is Linux upgrades *DO* reliably break programs that use dynamic linking. Dynamic libraries get - left out - changed incompatibly - moved some place else - changed compatibly but the version number altered so the dynamic linker doesn't believe it, or the foolsXXkind people who built the program wired in a demand for a particular version Indeed, every Linux upgrade I've had I've found myself screaming in frustration because programs *weren't* statically linked. (Which is the reason shared library support is important. I personally like my programs to keep working.) - -- brandon s. allbery [linux,solaris,freebsd,perl] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH -BEGIN PGP SIGNATURE- Version: GnuPG v2.0.10 (Darwin) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkx2rmMACgkQIn7hlCsL25XmjACgmWne8rR0EYeeHIBZvp2gywLp KDMAoKLGedOj5Dy2GXBo+NLcbCGemhS8 =XBmS -END PGP SIGNATURE- ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: Hackage on Linux
On Thu, Aug 26, 2010 at 20:51, Richard O'Keefe o...@cs.otago.ac.nz wrote: Maybe Linux is different. One thing is NOT different, and that is Linux upgrades *DO* reliably break programs that use dynamic linking. Dynamic libraries get - left out - changed incompatibly - moved some place else - changed compatibly but the version number altered so the dynamic linker doesn't believe it, or the foolsXXkind people who built the program wired in a demand for a particular version Indeed, every Linux upgrade I've had I've found myself screaming in frustration because programs *weren't* statically linked. Upgrading Linux should never, ever cause applications to stop working unless they were designed incorrectly in the first place. Low-level system libraries like glibc are the only code which needs to access Linux directly. However, most of the problems you mentioned (removed/modified dynamic libraries) are not part of Linux at all. If your distribution has poor quality control, you should consider switching to a better one -- I've heard good news about both Debian and RHEL in this area. Desktop-oriented distributions, such as Ubuntu or Fedora, are not suitable for long-term ( 6 years or so) installations. Haskell, of course, takes ABI pickiness to an absolute maximum. One of my most wished-for features is a way to provide C-style stable ABIs for Haskell shared libraries, so I could (for example) upgrade a support library and have every installed application pick it up. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe