Re: [Haskell-cafe] ByteString typechecking issues....
Hi Luke, joinhttp://cvs.haskell.org/Hugs/pages/libraries/base/Data-ByteString.html#v%3Ajoin:: ByteStringhttp://cvs.haskell.org/Hugs/pages/libraries/base/Data-ByteString.html#t%3AByteString- [ ByteStringhttp://cvs.haskell.org/Hugs/pages/libraries/base/Data-ByteString.html#t%3AByteString] - ByteStringhttp://cvs.haskell.org/Hugs/pages/libraries/base/Data-ByteString.html#t%3AByteString??? Vasili On Sat, Dec 27, 2008 at 1:58 AM, Luke Palmer lrpal...@gmail.com wrote: 2008/12/26 Galchin, Vasili vigalc...@gmail.com Hello, I have a ByteString - [ByteString] - ByteString situation, i.e. concatenation . -- marshall into ByteString representation join (encode (buildHeader ss)) -- ByteString (map encode (buildEntries (sequenceListExtract ss))) -- [ByteString] I get the following typecheck error which is vexing me Couldn't match expected type `t - t - B.ByteString' against inferred type `B.ByteString' ??? join is not a function in Data.ByteString. By the error I'm guessing you're getting the join from Control.Monad, instantiated to (-). You are looking for concat; i.e. concat $ encode (buildHeader ss) : -- ByteString map encode (buildEntries (sequenceListExtract ss)) -- [ByteString] (Control.Monad.join does end up meaningconcat when working on lists of lists, but it does not generalize to lists of other things). Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Request for feedback: Understanding Haskell Monads
Ertugrul == Ertugrul Soeylemez e...@ertes.de writes: Ertugrul Hello fellow Haskellers, In the last few weeks I have Ertugrul written a comprehensive tutorial about Haskell monads Ertugrul [1], and I was hoping to get some constructive feedback. Ertugrul I'd appreciate any well meant criticism. Ertugrul [1] http://ertes.de/articles/monads.html Speaker as a more-or-less beginner, this is excellent. -- Colin Adams Preston Lancashire ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function composition
* Oscar Picasso oscarpica...@gmail.com [2008-12-26 22:37:26-0500] Hi, I can write: *Main let yes = not . not *Main :t yes yes :: Bool - Bool But not: *Main let isNotEqual = not . (==) interactive:1:23: Couldn't match expected type `Bool' against inferred type `a - Bool' Probable cause: `==' is applied to too few arguments In the second argument of `(.)', namely `(==)' In the expression: not . (==) Why? You might want to read about currying[1]. This will explain why (==) does not take a pair of values, it rather takes one value and then another, and that's why it is not composable in the way you want. What you're trying to do is easier to do with uncurried functions: Prelude let isNotEqual = not . uncurry (==) Prelude :t isNotEqual isNotEqual :: (Eq a) = (a, a) - Bool Prelude isNotEqual (3,4) True Prelude isNotEqual (3,3) False (note that -XNoMonomorphismRestriction is used here) 1. http://www.haskell.org/haskellwiki/Currying -- Roman I. Cheplyaka :: http://ro-che.info/ Don't let school get in the way of your education. - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Function composition
* Roman Cheplyaka r...@ro-che.info [2008-12-27 11:33:22+0200] * Oscar Picasso oscarpica...@gmail.com [2008-12-26 22:37:26-0500] Hi, I can write: *Main let yes = not . not *Main :t yes yes :: Bool - Bool But not: *Main let isNotEqual = not . (==) interactive:1:23: Couldn't match expected type `Bool' against inferred type `a - Bool' Probable cause: `==' is applied to too few arguments In the second argument of `(.)', namely `(==)' In the expression: not . (==) Why? You might want to read about currying[1]. This will explain why (==) does not take a pair of values, it rather takes one value and then another, and that's why it is not composable in the way you want. What you're trying to do is easier to do with uncurried functions: Prelude let isNotEqual = not . uncurry (==) Prelude :t isNotEqual isNotEqual :: (Eq a) = (a, a) - Bool Prelude isNotEqual (3,4) True Prelude isNotEqual (3,3) False (note that -XNoMonomorphismRestriction is used here) 1. http://www.haskell.org/haskellwiki/Currying ... and isNotEqual = curry $ not . uncurry (==) is curried version, which has type isNotEqual :: (Eq b) = b - b - Bool -- Roman I. Cheplyaka :: http://ro-che.info/ Don't let school get in the way of your education. - Mark Twain ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
On Fri, 2008-12-26 at 15:38 +0100, Peter Verswyvelen wrote: Using GHCi I found it informative to see that IO indeed is a kind of state monad. Here's a GHCi session to show that: Prelude :m GHC.Prim Prelude GHC.Prim :i IO newtype IO a = GHC.IOBase.IO (State# RealWorld - (# State# RealWorld, a #)) -- Defined in GHC.IOBase instance Monad IO -- Defined in GHC.IOBase instance Functor IO -- Defined in GHC.IOBase So every IO a action takes the RealWorld as input, and outputs the RealWorld and some extra value a :) [snip] Thanks to all who've replied! So, the way I get it, everything in Haskell is a function, including IO. Moreover, there exist mathematical foundations for what functions are, in set theory and, more modern, more expressive, in category theory. However, some functions in Haskell may have side effects, like printing something on the screen, updating a database, or producing a random number. These functions are called 'actions' in Haskell. Now I'm starting to guess... There is no mathematical foundation for these side effects (likewise for persistent data), yet they are needed sometimes. However, there is a mechanism (sometimes) to compose functions using an extra type m a, m b, m c etc. instead of types a, b, c... This does not solve the problem concerning side effects, but it does provide a sort of 'Chinese boxes' to contain them within these type constructors m. Moreover, in the case of the type designation 'IO ...', you can't get anything out of the box. So now, at least, you've got a clean interface between the parts of your program which do not involve side effects, and the 'actions'. If I guess correctly, then the general statement 'monads are for actions' is wrong. It should be something like, 'monadic composition is a useful method of generalization, which, by the way, allows you to isolate side effects in a controlled manner'. Regards, Hans van Thiel ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ByteString typechecking issues....
Not in scope: `Data.ByteString.join' when Data.ByteString.join $ encode (buildHeader ss) -- ByteString -- [] (map encode (buildEntries (sequenceListExtract ss))) -- [ByteString] ?? Thanks, guys On Sat, Dec 27, 2008 at 3:13 AM, Eugene Kirpichov ekirpic...@gmail.comwrote: I think Luke meant that you forgot to qualify the import for join, and the compiler guessed that you are meaning the monad one, thus the error. 2008/12/27 Galchin, Vasili vigalc...@gmail.com: Hi Luke, join :: ByteString - [ByteString] - ByteString ??? Vasili On Sat, Dec 27, 2008 at 1:58 AM, Luke Palmer lrpal...@gmail.com wrote: 2008/12/26 Galchin, Vasili vigalc...@gmail.com Hello, I have a ByteString - [ByteString] - ByteString situation, i.e. concatenation . -- marshall into ByteString representation join (encode (buildHeader ss)) -- ByteString (map encode (buildEntries (sequenceListExtract ss))) -- [ByteString] I get the following typecheck error which is vexing me Couldn't match expected type `t - t - B.ByteString' against inferred type `B.ByteString' ??? join is not a function in Data.ByteString. By the error I'm guessing you're getting the join from Control.Monad, instantiated to (-). You are looking for concat; i.e. concat $ encode (buildHeader ss) : -- ByteString map encode (buildEntries (sequenceListExtract ss)) -- [ByteString] (Control.Monad.join does end up meaningconcat when working on lists of lists, but it does not generalize to lists of other things). Luke ___ 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: [Haskell] ANN: HLint 1.0
You were asking about getting the output of ':show modules' into a variable 'x', so that you can process it further. ':redir x :show modules' should do just that. There is another example command for implementing ':edit' this way (by now a native ghci command). I think I'm seeing your meaning. So that brings me up to this: let hlint _ = return $ unlines [:redir hlintvar1 :show modules, let hlintvar2 = map (fst . break (==',') . drop 2 . snd . break (== '(')) $ lines hlintvar1, :! hlint (concat $ intersperse \ \ hlintvar2] :def hlint hlint This doesn't work. The issue is that :! is weird; for it to work, one need to pass each argument as a separate string, and it won't evaluate a variable. It isn't just ':!', quoting/variable interpretation is generally rather uncomfortable in GHCi scripting (so much so that I originally submitted output redirection as a patch before figuring out that it could be done without patching GHCi - that surprise find was the motivation for posting my findings as an email). Have you tried reading the mini tutorial that I keep mentioning and which the using GHCi page is pointing to? Here's the direct link: http://www.haskell.org/pipermail/haskell-cafe/2007-September/032260.html The discussion is rather brief, but that tutorial has several examples that need to work around issues like this, ranging from simple but tedious construct-the-command-string to extra levels of ':cmd' in order to get extra levels of interpretation (when you need to construct a command string from a variable that will be bound via a constructed command string (see the definitions of ':find', ':le' or ':b(rowse)' - the latter is an example of using the info from ':show modules'). Claus ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ByteString typechecking issues....
Am Samstag, 27. Dezember 2008 18:42 schrieb Galchin, Vasili: Not in scope: `Data.ByteString.join' when Data.ByteString.join $ encode (buildHeader ss) -- ByteString -- [] (map encode (buildEntries (sequenceListExtract ss))) -- [ByteString] ?? Maybe you're looking for Data.ByteString.intercalate? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
Hans van Thiel wrote: However, some functions in Haskell may have side effects, like printing something on the screen, updating a database, or producing a random number. These functions are called 'actions' in Haskell. Not really true (disregarding things like unsafePerformIO). I haven't been following this thread, so I don't know if anybody else has suggested this, but perhaps it would be helpful to distinguish between evaluating expressions and performing actions. Evaluation is simply graph reduction, which is Haskell's only method of computation. There are no side-effects when you evaluate an expression (again, disregarding unsafePerformIO and company), even if that expression evaluates to an IO action. To perform an action is to cause the side-effect which that action represents. *You* never perform an action in Haskell. The runtime does. All you do is say how to evaluate those actions. Essentially, what the IO monad does is give you a DSL for constructing (by evaluation) effectful, imperative programs at runtime. The runtime will cause your program to evaluate the next action, then perform it, then cause your program to evaluate the next action, then perform it, and so on. At no point is the purity of your program broken by this. However, there is a mechanism (sometimes) to compose functions using an extra type m a, m b, m c etc. instead of types a, b, c... This does not solve the problem concerning side effects, but it does provide a sort of 'Chinese boxes' to contain them within these type constructors m. Moreover, in the case of the type designation 'IO ...', you can't get anything out of the box. So now, at least, you've got a clean interface between the parts of your program which do not involve side effects, and the 'actions'. This is another way to think of it. It is how I first thought of IO before I discovered the way I described above. It's a pretty good metaphor, and I don't think it's harmful, so you can stick with it for now if you would prefer. If I guess correctly, then the general statement 'monads are for actions' is wrong. It should be something like, 'monadic composition is a useful method of generalization, which, by the way, allows you to isolate side effects in a controlled manner'. Right on. Monads are extremely useful for things that don't involve side-effects. Hope this helps, - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Typeclass question
I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass question
On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner wagner.and...@gmail.com wrote: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Try this: {-# LANGUAGE ExistentialQuantification #-} data Foo = forall a. Bar a = Foo a Bool -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass question
On Sat, Dec 27, 2008 at 12:44 PM, David Menendez d...@zednenem.com wrote: On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner wagner.and...@gmail.com wrote: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Try this: {-# LANGUAGE ExistentialQuantification #-} data Foo = forall a. Bar a = Foo a Bool Though for existentials, I find GADT more natural (actually I find GADT more natural in most cases): data Foo where Foo :: Bar a = a - Foo Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass question
Seems like you want an existential type: data Foo = forall a. Bar a = Foo a Bool On 27 Dec 2008, at 22:24, Andrew Wagner wrote: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. ___ 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] Typeclass question
There is a disadvantage in GADTs. They don't work in Hugs. On 27 Dec 2008, at 22:49, Luke Palmer wrote: On Sat, Dec 27, 2008 at 12:44 PM, David Menendez d...@zednenem.com wrote: On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner wagner.and...@gmail.com wrote: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Try this: {-# LANGUAGE ExistentialQuantification #-} data Foo = forall a. Bar a = Foo a Bool Though for existentials, I find GADT more natural (actually I find GADT more natural in most cases): data Foo where Foo :: Bar a = a - Foo Luke ___ 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] Typeclass question
Hmm, I actually simplified my problem too much. What I actually want is: data Foo a = forall a. Bar a = Foo a Bool ...except I want the 'a' on the left to match the 'a' on the right, so that you can only construct values out of values of the parameterized type, which also must be of the Bar class. On Dec 27, 2008, at 1:44 PM, David Menendez d...@zednenem.com wrote: On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner wagner.and...@gmail.com wrote: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Try this: {-# LANGUAGE ExistentialQuantification #-} data Foo = forall a. Bar a = Foo a Bool -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
On Sat, Dec 27, 2008 at 4:50 PM, Hans van Thiel hthiel.c...@zonnet.nl wrote: However, some functions in Haskell may have side effects, like printing something on the screen, updating a database, or producing a random number. These functions are called 'actions' in Haskell. No :D I'll try to explain using the same picture that came into my mind when I first got what monads really are... Everything in Haskell is a function AND an Haskell function is always pure, i.e. has no side effects. Functions may return actions, which are a special kind of value even though they are no different to Haskell from values of any other type. When you are returning an action is like when you go to a driver and give him a car: the driver takes the car you gave him and takes it wherever the car is supposed to go. You build the car using small pieces (i.e. basic functions returning actions like putStrLn) and putting everything together using combinators (like = and or the do notation). So, the car in the example is an action (or, more formally, a value in a monad). Your Haskell functions (like putStrLn or anything) just return the car, but they don't run it: they are run at run-time by the Haskell run-time environment whose only task is to run values in the IO Monad, i.e. running the car. Even it may not be apparent for the IO Monad, every Monad value is run at some point in time: almost every monad is associated to at least a function running the monad: for the State Monad this is runState, for the Reader Monad is runReader and so on. The only exception to this is the IO Moand, which can be run only by the Haskell run time, implicitly: this is the reason why you'll never see a runIO thing. When the monad is run, it generate side-effects, like printing to screen, opening file and so on. If you're used to Unix administration, another image to understand monads are scripts. Haskell functions return script files that are run by the shell to affect the system they are run on. In the end, they are small pieces (the basic commands present in the system) put together by bash constructs, like for, while and so on. Hope this helps. -- Cristiano ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ByteString typechecking issues....
On 2008 Dec 27, at 12:42, Galchin, Vasili wrote: Not in scope: `Data.ByteString.join' Why are you trying to use join? It's not a string function; it's a function on lists which accidentally does something useful on normal Strings because they're implemented as lists. ByteStrings aren't lists, so there is no useful join, and ghc finds an instantiation of join somewhere else and does something unexpected as a result. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Typeclass question
Andrew Wagner wagner.andrew at gmail.com writes: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Sometimes it's enough to declare data Foo a = Foo a Bool and to put the 'Bar a =' context onto the functions and instances that involve Foo. For example, in Chris Okasaki's book Purely Functional Data Structures, the h in data BootstrapHeap h a = ... is always meant to satisfy 'Heap h =', but this is ensured by putting the context at all the points where a BootstrapHeap is created, and not exporting BootstrapHeap's data constructors. Regards, Tom ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ByteString typechecking issues....
2008/12/27 Brandon S. Allbery KF8NH allb...@ece.cmu.edu On 2008 Dec 27, at 12:42, Galchin, Vasili wrote: Not in scope: `Data.ByteString.join' Why are you trying to use join? It's not a string function; it's a function on lists which accidentally does something useful on normal Strings because they're implemented as lists. ByteStrings aren't lists, so there is no useful join, and ghc finds an instantiation of join somewhere else and does something unexpected as a result. It looks like in the docs he is looking athttp://cvs.haskell.org/Hugs/pages/libraries/base/Data-ByteString.html#v%3Ajoin, join is the name of intercalate. Use intercalate. Luke ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass question
Oh! That's much simplier: data Bar a = Foo a = Foo a Bool On 27 Dec 2008, at 23:09, Andrew Wagner wrote: Hmm, I actually simplified my problem too much. What I actually want is: data Foo a = forall a. Bar a = Foo a Bool ...except I want the 'a' on the left to match the 'a' on the right, so that you can only construct values out of values of the parameterized type, which also must be of the Bar class. On Dec 27, 2008, at 1:44 PM, David Menendez d...@zednenem.com wrote: On Sat, Dec 27, 2008 at 2:24 PM, Andrew Wagner wagner.and...@gmail.com wrote: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Try this: {-# LANGUAGE ExistentialQuantification #-} data Foo = forall a. Bar a = Foo a Bool -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ 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: Typeclass question
Tom Pledger wrote: Andrew Wagner wagner.andrew at gmail.com writes: I'm sure there's a way to do this, but it's escaping me at present. I want to do something like this: data Foo = Bar a = Foo a Bool ... That is, I want to create a new type, Foo, whose constructor takes both a Boolean and a value of a type of class Bar. Sometimes it's enough to declare data Foo a = Foo a Bool and to put the 'Bar a =' context onto the functions and instances that involve Foo. Although, if you really want to omit the `a` from the type, you can use the ExistentialQuantification extension or GADTs to do something like: -- with ExistentialQuantification data Foo = forall a . Bar a = Foo a Bool -- with GADTs data Foo where forall a . Bar a = Foo a Bool I haven't used either extension in a few months though, so I may have gotten the syntax wrong. You can look them up to be sure. - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass question
Andrew Wagner wrote: Hmm, I actually simplified my problem too much. What I actually want is: data Foo a = forall a. Bar a = Foo a Bool ...except I want the 'a' on the left to match the 'a' on the right, so that you can only construct values out of values of the parameterized type, which also must be of the Bar class. Well, you can ignore my previous contribution to this thread anyway. I failed to see the numerous other responses suggesting the same thing. I recommend against what you are wanting to do. It is probably nicer to have something like this: data Foo a = Foo a Bool -- don't export this foo :: Bar a = a - Bool - Foo a -- export this foo = Foo You can also use GHC's new ViewPatterns extension if you would still like to be able to pattern match on Foo values in other modules and don't mind being restricted to more recent versions of GHC. - Jake ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: hs-bibutils-0.1
Hello, I'm happy to announce the first release of hs-bibutils, the Haskell bindings to Chris Putnam's bibutils.[1] Bibutils is a library and a set of bibliographic utilities to interconvert between various bibliography database formats using a common MODS-format XML intermediate. hs-bibutils is meant to provide to citeproc-hs, and indirectly to pandoc, the ability to parse all the bibliographic database formats supported by bibutils. citeproc-hs[2] is a Haskell implementation of the Citation Style Language. It adds to pandoc a Bibtex like citation and bibliographic formatting and generation facility. DOWNLOADS hs-bibutils can be downloaded from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/hs-bibutils The project home page can be found here: http://code.haskell.org/hs-bibutils/ INSTALLATION AND KNOWN ISSUES bibutils builds, without installing it, a static library to be used to compile the various converting utilities. But in order to use the library with pandoc (or ghci) it is necessary to create and install a shared object before building and installing hs-bibutils. hs-bibutils provides a patch to the bibutils building scripts to enable the shared object creation and installation. Alternatively a patched version of the latest release of bibutils can be downloaded from the project home page, where all the needed information for the installation are provided: http://code.haskell.org/hs-bibutils/#installation I was able to test the patched building scripts only on a Linux machine with a x86 system. Please report me any success or failure on other systems/architectures. BUG REPORTS To submit bug reports you can either contact me directly or use the citeproc-hs bug tracking system available at the following address: http://code.google.com/p/citeproc-hs/issues Hope you'll enjoy, Andrea Rossato [1] http://www.scripps.edu/~cdputnam/software/bibutils/ [2] http://code.haskell.org/citeproc-hs/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] ANNOUNCE: citeproc-hs-0.2
Hello, I'm happy to announce the release of citeproc-hs-0.2. WHAT'S NEW 1. Added support for citation collapsing options. This fills the last major gap to a usable CSL implementation; 2. added a wrapper around hs-bibutils[1] (disabled by default). By installing hs-bibutils and linking citeproc-hs to it with the '-fbibutils' configuration flag, it is possible to read all the bibliographic databases supported by bibutils[2]; 3. added some haddock API documentation: http://code.haskell.org/citeproc-hs/docs/ 4. simplified and started to document the internals of the library. DOWNLOADS citeproc-hs can be downloaded from Hackage: http://hackage.haskell.org/cgi-bin/hackage-scripts/package/citeproc-hs ABOUT citeproc-hs is a Haskell implementation of the Citation Style Language. It adds to pandoc, the famous Haskell text processing tool, a Bibtex like citation and bibliographic formatting and generation facility. The Citation Style Language (CSL) is an XML language for specifying citation and bibliographic formatting, similar in principle to BibTeX .bst files or the binary style files in commercial products like Endnote or Reference Manager. CSL is used by Zotero for bibliographic style formatting, and a huge number of CSL styles have been developed by the Zotero community. More information, with installation instructions, can be found here: http://code.haskell.org/citeproc-hs/ Hope you'll enjoy, Andrea Rossato [1] http://code.haskell.org/hs-bibutils/ [2] http://www.scripps.edu/~cdputnam/software/bibutils/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] What are side effects in Haskell?
On 2008 Dec 27, at 15:16, Cristiano Paris wrote: On Sat, Dec 27, 2008 at 4:50 PM, Hans van Thiel hthiel.c...@zonnet.nl wrote: However, some functions in Haskell may have side effects, like printing something on the screen, updating a database, or producing a random number. These functions are called 'actions' in Haskell. Functions may return actions, which are a special kind of value even though they are no different to Haskell from values of any other type. There is another way to think about it (which happens to also be the way GHC implements it): an action is just a partially applied function. In the case of IO, the missing value is the state, which has the opaque internal type RealWorld# that can't normally be instantiated. (unsafePerformIO works by using an internal function which synthesizes a value of type RealWorld#. Since all the IO code *and* the code generator in GHC assume this can't be done, unsafePerformIO is capable of confusing things rather badly. In particular, you need to tell GHC to inline any code using unsafePerformIO because otherwise it can make incorrect assumptions and very strange behavior will result. UnsafeInterleaveIO is even sneakier: it clones the hidden RealWorld# value, which brings its own kinds of confusion into the mix.) In the normal course of events, your program becomes a long chain of unapplied functions (think foo. bar . baz . (...)), waiting for something to inject a RealWorld# into it. This is the value of main. Conceptually, the runtime then injects a RealWorld# and the program runs. (In reality, GHC knows that code doesn't actually have to be generated to carry RealWorld# values around, so the generated program ends up looking more or less normal.) -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Typeclass question
On Sat, Dec 27, 2008 at 3:09 PM, Andrew Wagner wagner.and...@gmail.com wrote: Hmm, I actually simplified my problem too much. What I actually want is: data Foo a = forall a. Bar a = Foo a Bool ...except I want the 'a' on the left to match the 'a' on the right, so that you can only construct values out of values of the parameterized type, which also must be of the Bar class. Something like this? {-# LANGUAGE ExistentialQuantification #-} class Bar a where bar :: a - a data Foo a = (Bar a) = Foo a Bool baz :: Foo a - a baz (Foo a _) = bar a This works fine for me with GHC 6.8, but I'd expect Hugs and earlier versions of GHC to reject it. See section 8.4.5 of the GHC manual. http://www.haskell.org/ghc/docs/latest/html/users_guide/data-type-extensions.html#gadt-style -- Dave Menendez d...@zednenem.com http://www.eyrie.org/~zednenem/ ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Missing Network Functions
While working on a project, I discovered that hton[sl] and ntoh[sl] are missing from the networking libraries. It appears there was some justification for this, but I've fallen upon a few instances where things were *not* working as expected. (Specifically when newtype'ing around HostAddress.) As such, I'm putting together a few extra functions that I think should exist in Network somewhere. I'm calling the package Network.Util (but am open to changes). Currently this only has: - htons - htonl - ntohs - ntohl Before I drop this on hackage: 1. Is there a reason I shouldn't do this? 2. Are there other suggestions for missing functions? (preferably cross-platform suggestions) Thanks all. /jve ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Re: Missing Network Functions
I want to group them with Network functions because traditionally these specific functions *are* in networking packages. On *nix systems, the prototypes reside in netinet/in.h. On Windows they reside in winsock2.h and one must link against libws2_32. The package I have locally supports all platforms. It just does a foreign import of the function (and uses a preprocessor definition to pick the calling convention). One could make an argument to add these sorts of functions to Word and Int packages. /jve On Sat, Dec 27, 2008 at 7:14 PM, Chris Kuklewicz hask...@list.mightyreason.com wrote: Are these going to be available on Windows or just Posix systems? And these are NOT performing network communication. They are bit manipulations. I could imagine putting them in/under the Data.Word or Data.Bits more than Network.* And they should also be made to work with the corresponding Foreign.C.Types of CShort, etc. John Van Enk wrote: While working on a project, I discovered that hton[sl] and ntoh[sl] are missing from the networking libraries. It appears there was some justification for this, but I've fallen upon a few instances where things were *not* working as expected. (Specifically when newtype'ing around HostAddress.) As such, I'm putting together a few extra functions that I think should exist in Network somewhere. I'm calling the package Network.Util (but am open to changes). Currently this only has: * htons * htonl * ntohs * ntohl Before I drop this on hackage: 1. Is there a reason I shouldn't do this? 2. Are there other suggestions for missing functions? (preferably cross-platform suggestions) Thanks all. /jve ___ 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] Don't make 'show*' functions
G'day all. Quoting Jeff Heard jefferson.r.he...@gmail.com: I don't think that making Show a type class was a mistake. I don't either. Two main reasons: 1. [Char] should not be shown ['l','i','k','e',' ','t','h','i','s']. 2. Default implementations of Show can break abstractions by leaking implementation details. I think that we have long since overloaded the meaning of Show and made it ambiguous. There are multiple distinct reasons people use Show, and this gets confusing. It would be good if we as a community tried to nail down these different meanings that people tend to attach to Show and fork out new type classes that each encompass those meanings. Text is useful and often ignored as a means of debugging, inspecting, logging, and serializing. I tend to agree. Some thoughts: - Show is what print outputs and what GHCi reports. Therefore, to most programmers, it's primarily for human-readability regardless of what the standard says. - Read is barely useful as-is. Don't get me wrong; the read function has a very handy interface, especially if all you need is to convert a String into an Integer. But I'd wager that the majority of the most expert of expert Haskellers couldn't write a custom Read instance without constantly referring to the documentation and/or example code. In addition, very few people are aware of the performance characteristics of reads. - If you want serialisation and deserialisation, Show and Read are poorly-suited for it. A real solution requires handling tricky cases like versioning, redundancy (e.g. computed fields), smart constructors etc. - If what you actually want is parsing and/or pretty-printing, we have some great solutions for that. Cheers, Andrew Bromage ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Missing Network Functions
2008/12/27 John Van Enk vane...@gmail.com Currently this only has: - htons - htonl - ntohs - ntohl This is all subsumed by the binary package (Data.Binary), where it makes a lot more sense in any instance. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Re: [Haskell] ANN: HLint 1.0
-BEGIN PGP SIGNED MESSAGE- Hash: SHA512 On Fri, Dec 26, 2008 at 5:22 PM, Claus Reinke wrote: You were asking about getting the output of ':show modules' into a variable 'x', so that you can process it further. ':redir x :show modules' should do just that. There is another example command for implementing ':edit' this way (by now a native ghci command). I think I'm seeing your meaning. So that brings me up to this: let hlint _ = return $ unlines [:redir hlintvar1 :show modules, let hlintvar2 = map (fst . break (==',') . drop 2 . snd . break (== '(')) $ lines hlintvar1, :! hlint (concat $ intersperse \ \ hlintvar2] :def hlint hlint This doesn't work. The issue is that :! is weird; for it to work, one need to pass each argument as a separate string, and it won't evaluate a variable. -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (GNU/Linux) iEYEAREKAAYFAklW2+4ACgkQvpDo5Pfl1oJlnACdGLV9HyfyyBu3goNG9dTqC0ha dFQAn0kzcIcMhSQ4tniurBTZHmQ6zBhC =YVir -END PGP SIGNATURE- It isn't just ':!', quoting/variable interpretation is generally rather uncomfortable in GHCi scripting (so much so that I originally submitted output redirection as a patch before figuring out that it could be done without patching GHCi - that surprise find was the motivation for posting my findings as an email). No kidding. I find ghci scripting pretty awkward. Maybe things would be better if all the :commands had exposed and easily used Haskell function equivalents so you could stay on the Haskell level and only deal with the :commands at the last second. Have you tried reading the mini tutorial that I keep mentioning and which the using GHCi page is pointing to? Here's the direct link: http://www.haskell.org/pipermail/haskell-cafe/2007-September/032260.html The discussion is rather brief, but that tutorial has several examples that need to work around issues like this, ranging from simple but tedious construct-the-command-string to extra levels of ':cmd' in order to get extra levels of interpretation (when you need to construct a command string from a variable that will be bound via a constructed command string (see the definitions of ':find', ':le' or ':b(rowse)' - the latter is an example of using the info from ':show modules'). Claus Yes, I have read all that, but I find it difficult to understand. In some places, there are more levels of quoting and indirection than I can keep track of (I swear in one place the code must've been 4 levels deep). But on re-reading, I think :cmd solves my problem. So my solution looks like this: let hlint _ = return $ unlines [:redir hlintvar1 :show modules, let hlintvar2 = map (fst . break (==',') . drop 2 . snd . br eak (== '(')) $ lines hlintvar1, :cmd return (\:! hlint \ ++ (concat $ intersperse \ \ hlintvar2))] :def hlint hlint (:redir obviously coming from your .ghci code.) This doesn't integrate with :load or anything, but it does let you just blindly go ':hlint' and get the suggestions. -- gwern ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] chroot a single thread
Hello, I am working on an application where I would like to chroot a thread, but I am not seeing a way to do it. I already have code which can run an IO action inside a chroot. The type signature is: fchroot :: FilePath - IO a - IO a The first argument is the new root, the second argument is the action to run with that root. You can see the implementation here if you are curious: http://src.seereason.com/build-env/Chroot.hs The problem with that function is that chroot affects the root of the whole process. In a single-threaded program this is (possibly) ok, because the original root is restored after the IO action completes (though with unsafeInterleaveIO, perhaps bad stuff will happen). In a multithreaded program it can be disasterous. As far as I know, the only solution would be to implement a function like fchroot which looks more like: pchroot :: FilePath - IO () - IO ExitCode Here the IO action would be forked off and run in a whole new process so that changing its root does not affect other 'threads'. Of course, you also can't use any of the nifty Haskell intra-thread communication stuff. Basically you can pass some values in and get back an exit code. However, I am not even sure how to implement a useful version of pchroot. In theory, I can just use forkProcess, but, the Giant Warning for forkProcess indicates that this will not be very useful in practice: forkProcess comes with a giant warning: since any other running threads are not copied into the child process, it's easy to go wrong: e.g. by accessing some shared resource that was held by another thread in the parent. Another example is the I/O manager thread: since the I/O manager isn't running in the child, attempting to do any Handle-based I/O will deadlock. Anyone have an ideas ? Thanks! - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Missing Network Functions
Would it make sense to write wrappers of Data.Binary functions to emulate the networking functions that are usually expected? /jve On Sat, Dec 27, 2008 at 8:23 PM, Bryan O'Sullivan b...@serpentine.comwrote: 2008/12/27 John Van Enk vane...@gmail.com Currently this only has: - htons - htonl - ntohs - ntohl This is all subsumed by the binary package (Data.Binary), where it makes a lot more sense in any instance. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] ByteString typechecking issues....
Brandon, I am solely operating based on the type signatures of function .. hence I picked Data.ByteString.Join :: ByteString - [ByteString] - ByteString ... Vasili On Sat, Dec 27, 2008 at 2:21 PM, Brandon S. Allbery KF8NH allb...@ece.cmu.edu wrote: On 2008 Dec 27, at 12:42, Galchin, Vasili wrote: Not in scope: `Data.ByteString.join' Why are you trying to use join? It's not a string function; it's a function on lists which accidentally does something useful on normal Strings because they're implemented as lists. ByteStrings aren't lists, so there is no useful join, and ghc finds an instantiation of join somewhere else and does something unexpected as a result. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allb...@kf8nh.com system administrator [openafs,heimdal,too many hats] allb...@ece.cmu.edu electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] chroot a single thread
On Sat, Dec 27, 2008 at 8:01 PM, Jeremy Shaw jer...@n-heptane.com wrote: The problem with that function is that chroot affects the root of the whole process. Yeah. Maybe you want privilege separation. Instead of starting a thread to do the stuff that requires extra authority, make it a separate program and communicate with it with some simple protocol. qmail might be good to look at to get the intuition. You say you can only pass data and get back return codes, but really, you can send and receive whatever you want if the other process does I/O via a UNIX domain socket or something like that. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] chroot a single thread
At Sat, 27 Dec 2008 22:41:58 -0600, brian wrote: On Sat, Dec 27, 2008 at 8:01 PM, Jeremy Shaw jer...@n-heptane.com wrote: The problem with that function is that chroot affects the root of the whole process. Yeah. Maybe you want privilege separation. Instead of starting a thread to do the stuff that requires extra authority, make it a separate program and communicate with it with some simple protocol. qmail might be good to look at to get the intuition. In my case, it's not really a privilege / authority issue -- the goal is to be able to build chroot's to simulate different environments and then run code and applications in those environments. The primary use right now is an automated build system. The current solution has been to use 'system' and the chroot exectuable, but that has it's limitations. You say you can only pass data and get back return codes, but really, you can send and receive whatever you want if the other process does I/O via a UNIX domain socket or something like that. Yeah, I originally had some comments about forking off a seperate processing and talking to it via some sort of IPC. But, I left it out to see what other people would come up with :) Alas, fchroot is such a small, simple little function that can leverage the existing Haskell thread communication stuff. It is shame that to isolate the chroot to a single thread, requires such a significantly different approach. But, that is unix's fault not Haskell's. - jeremy ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe