[Haskell-cafe] Munich Haskell Meeting
Dear Haskellers, our monthly get-togethers in Munich this year start on Thursday, 31ts of January at 19h30. Our meeting venue will be Cafe Puck once again. If you want to join, please go to http://www.haskell-munich.de/dates and click the button. Of course, you can also invite all those interested in functional programming. Have a successful week, Heinrich ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Mac os x (Intel, 10.6.8) problem compiling yesod-core-1.1.7.1
Hello GHC version : 7.4.2 When I do a cabal-dev instal yesod-core, I get the following error: Loading package blaze-builder-conduit-0.5.0.3 ... linking ... done. Loading package hashable-1.2.0.5 ... linking ... ghc: lookupSymbol failed in resolveImports /Users/V3/windev/Haskell/Z/cabal-dev//lib/HShashable-1.2.0.5.o: unknown symbol `_hashable_siphash24_sse2' ghc: unable to load package `hashable-1.2.0.5' Has anyone encountered the same problem? Thank you J-C ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] catamorphisms and attribute grammars
Patrick Bahr does something very similar in Modular Tree Automata [1], also noting the relation to attribute grammars. It's implemented in the compdata package [2]. [1] Patrick Bahr, Modular Tree Automata (MPC 2012), http://dx.doi.org/10.1007/978-3-642-31113-0_14 [2] http://hackage.haskell.org/package/compdata / Emil 2013-01-26 23:03, Petr P skrev: Dear Haskellers, I read some stuff about attribute grammars recently [1] and how UUAGC [2] can be used for code generation. I felt like this should be possible inside Haskell too so I did some experiments and I realized that indeed catamorphisms can be represented in such a way that they can be combined together and all run in a single pass over a data structure. In fact, they form an applicative functor. [1] http://www.haskell.org/haskellwiki/Attribute_grammar [2] Utrecht University Attribute Grammar Compiler To give an example, let's say we want to compute the average value of a binary tree. If we compute a sum first and then count the elements, the whole tree is retained in memory (and moreover, deforestation won't happen). So it's desirable to compute both values at once during a single pass: -- Count nodes in a tree. count' :: (Num i) = CataBase (BinTree a) i count' = ... -- Sums all nodes in a tree. sum' :: (Num n) = CataBase (BinTree n) n sum' = ... -- Computes the average value of a tree. avg' :: (Fractional b) = CataBase (BinTree b) b avg' = (/) $ sum' * count' Then we can compute the average in a single pass like runHylo avg' treeAnamorphism seed My experiments together with the example are available at https://github.com/ppetr/recursion-attributes I wonder, is there an existing library that expresses this idea? Best regards, Petr Pudlak ___ 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] Suggestiong for inter-thread communication
On 13-01-26 05:28 AM, Erik de Castro Lopo wrote: Thiago Negri wrote: Do you need advice on what? I didn't understand your last phrase. Well I have data from two sources, stdin and the calculation thread. If I was doing this in C, I'd probably use a pipe for the calculation data and then do select on the two file descriptors. There is a select package: http://hackage.haskell.org/package/select but I was wondering if there was a more idiomatic Haskell way of dealing with inputs from more than one source. There are list arrows, and also coroutines in many guises including pipes, conduits, and iteratees. These are all co-operative concurrency, however, and I can't tell if your problem requires pre-emptive threads. ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Mac os x (Intel, 10.6.8) problem compiling yesod-core-1.1.7.1
Adding Bryan, who wrote this code. On Mon, Jan 28, 2013 at 1:23 AM, jean-christophe mincke jeanchristophe.min...@gmail.com wrote: Hello GHC version : 7.4.2 When I do a cabal-dev instal yesod-core, I get the following error: Loading package blaze-builder-conduit-0.5.0.3 ... linking ... done. Loading package hashable-1.2.0.5 ... linking ... ghc: lookupSymbol failed in resolveImports /Users/V3/windev/Haskell/Z/cabal-dev//lib/HShashable-1.2.0.5.o: unknown symbol `_hashable_siphash24_sse2' ghc: unable to load package `hashable-1.2.0.5' Has anyone encountered the same problem? Thank you J-C ___ 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] Uniplate and rewriting with different types
Hi all, I have a question about the Uniplate library, regarding rewriting with transformations that have different types. With the following type, and transformation functions: data Odd = OddOne Even | OddZero Even deriving (Data,Typeable,Show) data Even = EvenOne Odd | EvenZero Odd | Nil deriving (Data,Typeable,Show) t1,t2,t3 :: Even - Maybe Even t1 (EvenOne (OddOne x)) = Just $ EvenOne (OddZero x) t1 x= Nothing t2 (EvenOne (OddZero x)) = Just $ EvenZero (OddOne x) t2 x = Nothing t3 (EvenZero (OddOne x)) = Just $ EvenZero (OddZero x) t3 x = Nothing it is easy to combine the transformations into a single transformation, because they all have the same type. The result can then be passed to the Uniplate's rewriteBi function: allts x = t1 x `mplus` t2 x `mplus` t3 x example = OddOne (EvenOne (OddOne (EvenOne (OddOne Nil go = rewriteBi allts example But if one of the transformations has a different type, you can't do it this way. For instance, redefine t2 to have a different type: t2 :: Odd - Maybe Odd t2 (OddZero (EvenOne x)) = Just $ OddZero (EvenZero x) t2 x = Nothing and you are stuck because the functions of different types can't be combined into a single transformation. My question is: is there a good way to combine the transformation functions if they have different types? I have come up with a possible solution (see below), but I am not sure that it is the right approach, and it is probably inefficient. Chris Mears {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE ScopedTypeVariables #-} import Control.Monad import Control.Monad.State import Data.Generics import Data.Generics.Uniplate.Data data Odd = OddOne Even | OddZero Even deriving (Data,Typeable,Show) data Even = EvenOne Odd | EvenZero Odd | Nil deriving (Data,Typeable,Show) t1 (EvenOne (OddOne x)) = Just $ EvenOne (OddZero x) t1 x= Nothing t2 :: Odd - Maybe Odd t2 (OddZero (EvenOne x)) = Just $ OddZero (EvenZero x) t2 x = Nothing t3 (EvenZero (OddOne x)) = Just $ EvenZero (OddZero x) t3 x = Nothing -- The transformers are wrapped in an existential type. data WrappedTransformer from = forall to. (Data to, Biplate from to) = WrappedTransformer (to - Maybe to) -- Apply a single transformation, and return Just x if the -- transformation fired (where x is the result of the rewriting), and -- Nothing if no transformation fired. rewriteBiCheck :: Biplate from to = (to - Maybe to) - from - Maybe from rewriteBiCheck f e = case runState (rewriteBiM check e) False of (e', True) - Just e' (_, False) - Nothing where check x = case f x of Nothing - return Nothing Just y - put True return (Just y) -- Apply a list of wrapped transformations until no more -- transformations can be applied. rewriteBiList :: forall from. [WrappedTransformer from] - from - from rewriteBiList transformers m = go transformers m where go :: [WrappedTransformer from] - from - from go [] m = m go ((WrappedTransformer t):ts) m = case rewriteBiCheck t m of Just m' - go transformers m' Nothing - go ts m -- Test case. example = OddOne (EvenOne (OddOne (EvenOne (OddOne Nil go = rewriteBiList [ WrappedTransformer t1 , WrappedTransformer t2 , WrappedTransformer t3 ] example ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] quotRem and divMod
Hi! I’ve always thought that `quotRem` is faster than `quot` + `rem`, since both `quot` and `rem` are just wrappers that compute both the quotient and the remainder and then just throw one out. However, today I looked into the implementation of `quotRem` for `Int32` and found out that it’s not true: quotRem x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError | x == minBound y == (-1) = overflowError | otherwise = (I32# (narrow32Int# (x# `quotInt#` y#)), I32# (narrow32Int# (x# `remInt#` y#))) Why? The `DIV` instruction computes both, doesn’t it? And yet it’s being performed twice here. Couldn’t one of the experts clarify this bit? ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache
Hi, I'm relatively new to Haskell, and consider myself to be towards the beginner side of the scale. Nevertheless, I've got this Haskell program I've been working on that's sitting around 11k lines right now. The pattern has been to let it grow to then knock it back by 'refactoring' or whatever you want to call it… doing it right the second time maybe… or the third time. All I want to get across is that though I consider myself a Haskell beginner I've still managed to produce something that is actually quite complex and of reasonable size in about three months. I'm still getting caught by stuff that I should not be caught by. So. Today I thought it was about time to simplify how new 'things' of a certain kind are added to the system. These things are some a cross between an event and an assertion of a fact in a rule based system. There are many different kinds of these things. I already have more than a dozen commonplace ones, and I expect there's a much larger number of more specialized ones that a user will want to add on their own. While they start out quite differently, they end up satisfying a common interface and follow the identical three or four state lifecycle. This sounded like a type class to me, and in fact, easily implemented as such. Now, this is how I got caught: it seems to be impossible to have collections of things with a common type class if they have different types. How is it that I've written that many lines of code in Haskell and I'm just noticing this now? (If I wasn't so annoyed, I'd look for something clever to reflect how loc count obviously doesn't mean much… but clever seems to be beyond me today). Is this true? Are there any GHC extensions that will let me around this? The immediate problem is mapping an input to the system, some json message containing a reference to the 'thing' (like a key of some kind). I have to take that reference and find the thing and operate on it. All operations are easily accommodated by a type class. However, since I can't have a collection with mixed types even if the types satisfy a type class, I can't quite see how to actually store the things so I can find them. So there are a couple of obvious ways to handle this. I could use an ADT and a sum type of all the known kinds of thing, but I already know that this has to be extended and that's going to be problematic with users doing this on their own. And the type signatures look ugly. So I think that's not the best. I could use an ADT that contains functions that correspond to the functions of the type class, and that close over the 'thing' in question. I think this could be made to work, but I'm concerned with walking into more nasty surprises… If anyone is able to make sense of what I wrote and has any suggestions I'd really appreciate hearing them. Thanks, Bob ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache
If I understand your message well enough, I think you are looking for GHC's `ExistentialQuantification` extension. Building heterogeneous collections is a common example of what existential types are useful for. Take a look at this wiki page [1]; there is an example of how to accomplish this there, along with a handful of other techniques. [1] http://www.haskell.org/haskellwiki/Heterogenous_collections#Existential_types signature.asc Description: Digital signature ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Type classes, collections, sum types, closures, and a massive headache
On Mon, Jan 28, 2013 at 5:43 PM, Bob Hutchison hutch-li...@recursive.cawrote: Now, this is how I got caught: it seems to be impossible to have collections of things with a common type class if they have different types. How is it that I've written that many lines of code in Haskell and I'm just noticing this now? (If I wasn't so annoyed, I'd look for something clever to reflect how loc count obviously doesn't mean much… but clever seems to be beyond me today). Is this true? Are there any GHC extensions that will let me around this? I just encountered this recently myself. There is a GADT extension [1][2] that may help. The greater abstraction appears to lie in existential types [3]. That being said, I'm a beginner as well and haven't yet used these extensions. So far I have found that my code is simplified by redefining heterogeneous types in terms of homogeneous functions. If I have a class that implements common methods, I will reorganize lists by common function types rather than by class. Cheers, Darren --- [1] http://www.haskell.org/haskellwiki/GADT [2] http://www.haskell.org/haskellwiki/GADTs_for_dummies [3] http://www.haskell.org/haskellwiki/Existential_type ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] quotRem and divMod
On Mon, Jan 28, 2013 at 4:27 PM, Artyom Kazak artyom.ka...@gmail.com wrote: Hi! I’ve always thought that `quotRem` is faster than `quot` + `rem`, since both `quot` and `rem` are just wrappers that compute both the quotient and the remainder and then just throw one out. However, today I looked into the implementation of `quotRem` for `Int32` and found out that it’s not true: quotRem x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError | x == minBound y == (-1) = overflowError | otherwise = (I32# (narrow32Int# (x# `quotInt#` y#)), I32# (narrow32Int# (x# `remInt#` y#))) Why? The `DIV` instruction computes both, doesn’t it? And yet it’s being performed twice here. Couldn’t one of the experts clarify this bit? That code is from base 4.5. Here's base 4.6: quotRem x@(I32# x#) y@(I32# y#) | y == 0 = divZeroError -- Note [Order of tests] | y == (-1) x == minBound = (overflowError, 0) | otherwise = case x# `quotRemInt#` y# of (# q, r #) - (I32# (narrow32Int# q), I32# (narrow32Int# r)) So it looks like it was improved in GHC 7.6. In particular, by this commit: http://www.haskell.org/pipermail/cvs-libraries/2012-February/014880.html Shachaf ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] Most used functions in hackage
Hi, I'm guessing this is a long shot, but Is there any link that counts the use of all functions in all packages in Hackage and lists them by frequency or by other stats? I'm still new to haskell but I've been working my way through tons and tons of tutorials and books. It would be very helpful to target in on the current reality of the most critical functions. Anything like this out there? Thanks, Casey ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] Most used functions in hackage
On 01/29/2013 11:21 AM, Casey Basichis wrote: Is there any link that counts the use of all functions in all packages in Hackage and lists them by frequency or by other stats? I'm still new to haskell but I've been working my way through tons and tons of tutorials and books. It would be very helpful to target in on the current reality of the most critical functions. Hello Casey, You can use Hoogle http://www.haskell.org/hoogle/ to get information about a particular function or to find a function by a part of it's signature. While it's helpful to carefully study some basic modules like Prelude function by function, I don't think it's a good approach in general. I suggest you to look for reviews of popular modules. Personally, I found 24 days of hackage http://ocharles.org.uk/blog/ to be quite informative. I wouldn't argue it's a best source for a beginner, but at least it gives quite a broad perspective. Best regards, Dmitry ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe