News aggregator

loop problem

haskell-cafe - Sat, 05/10/2014 - 3:32pm
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

feedly.com

del.icio.us/haskell - Sat, 05/10/2014 - 2:05pm
Categories: Offsite Blogs

feedly.com

del.icio.us/haskell - Sat, 05/10/2014 - 2:05pm
Categories: Offsite Blogs

Benchmarking Haskell compilers.

Haskell on Reddit - Sat, 05/10/2014 - 1:20pm

Hi Haskell community.

I'm benchmarking Haskell compilers but most of the benchmarks I have are completely contrived and don't relate to how Haskell is used in the wild. So, I'm looking for libraries which are in common use (ie. they're on hackage) and easy to benchmark. The haskell-src-exts package is an example of what I'm looking for. One benchmark result for parsing Haskell code is worth more than all the fibonacci, n-queens, and prime number benchmarks put together. Please help me find more libraries where performance improvements actually matter.

So, if you're using a Haskell library for anything CPU intensive, please let me know. I'd love to include it in my benchmark suite.

The end result will look something like this: http://mirror.seize.it/linux-ghc-7.8.2-2014.05.11.html and this http://mirror.seize.it/linux-ajhc-ghc-uhc-2014.05.11.html

(PS. I've already looked at nofib and fibon.)

submitted by Lemmih
[link] [19 comments]
Categories: Incoming News

what did I do wrong

haskell-cafe - Sat, 05/10/2014 - 12:51pm
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Haskell-mode documentation

Haskell on Reddit - Sat, 05/10/2014 - 12:51pm
Categories: Incoming News

Bug in GHC (probably parser) regarding GADTs

haskell-cafe - Sat, 05/10/2014 - 11:53am
The following does not work: data Foo a where {Foo :: (->) a (Foo a)} Someone please file a bug for me, I can't on my computer. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Back to Emacs

del.icio.us/haskell - Sat, 05/10/2014 - 11:00am
Categories: Offsite Blogs

www.haskell.org

del.icio.us/haskell - Sat, 05/10/2014 - 10:27am
Categories: Offsite Blogs

fvisser.nl

del.icio.us/haskell - Sat, 05/10/2014 - 7:58am
Categories: Offsite Blogs

Haddock issue tracker is now on GitHub.

haskell-cafe - Sat, 05/10/2014 - 7:40am
Greetings, The Haddock issue tracker now lives at [1]. The reasoning is that a lot of people have a GitHub account already and signing up just for Trac is tedious. Hopefully this will also allow people to see more easily what's going on. This also removes the maintenance load from Haskell infrastructure: the Trac instance has been bitrotting quite a bit and recently even sending out e-mail about tickets stopped working. Old issues have been migrated over so the ticket numbers still correspond. Please file any new issues or make issue comments on GitHub. If you do not wish to use GitHub (which is fairly understandable) then please send me the report directly and I will create one for you. Thanks. [1]: https://github.com/haskell/haddock/issues?state=open
Categories: Offsite Discussion

Custome monoid mappend on HashMap and HashSet values

haskell-cafe - Sat, 05/10/2014 - 6:48am
Hello, Does anyone have an example on how I might be able to use monoids to mappend a HashMap Int (HashMap Int Int) together? Cheers, -John
Categories: Offsite Discussion

Is there a GHC light? I love haskell, but I can't ask my users to download 120 megabytes of GHC madness just to compile and run my stupid program.

Haskell on Reddit - Sat, 05/10/2014 - 4:45am

The docker folks said they moved to go from python because go code can be statically compiled. GHC doesn't seem to have this advantage. It links it's binarries to specific glibc versions. When Joey Hess makes his binary release of git annex, he ends up packing glibc into a tarbal with the binary ! :( https://git-annex.branchable.com/install/Linux_standalone/

I've actually been considering writting code in haskell 98 just to be able to tell people to install Hugs(which is smaller).

Does anyone else have suggestions on how to actually ship haskell code?

submitted by timthelion
[link] [75 comments]
Categories: Incoming News

language-puppet: 7 Startups - part 1 - Introduction and types

Planet Haskell - Sat, 05/10/2014 - 2:14am

There have been recently complaints that there wasn’t any resource available for bridging the gap between beginner and experimented Haskeller, and some posts on “Haskell program architecture” have been written to help with this transition. I have found these posts to be pretty interesting, and while I can hardly be called an expert, I would like to contribute to this effort by documenting a few advanced Haskell features, as well as my design decisions, applied to a simple, yet fun, project.

Now that this is out of the way, let’s start !

The project

In this series of posts, I will describe how to model the rules of a well known board game, and how to turn them in an enjoyable program. If time permits, quite a few topics should be discussed, including key design decisions, how to interface a pure description of the rules with multiple backends, concurrency with the STM, and the advantage of always pretty printing your data structures.

The game itself is a shameless clone of the excellent 7 Wonders game (you can find the rules on the official web site), but with Internet giants instead of antique wonders. The theming took me a long time, and I am not particularly satisfied with it, so if you feel like contributing, please give me better names for the cards and resources.

All the code is on github. I will document my decisions and actions as I go, and will tag the repository accordingly. The relevant version for this article is tag Step1.1.

The types Startups.Base

The Startups.Base module contains all the base elements of the game, with the relationship with the original game written the comments. While all the types are more or less directly transcribed from the rules book, the newtyped numerical types might not be obvious :

<figure class="code"> 1 2 3 4 5 6 7 8 9 10 11 newtype Poacher = Poacher { getPoacher :: Integer } deriving (Ord, Eq, Num, Integral, Real, Enum, Show) newtype VictoryPoint = VictoryPoint { getVictory :: Integer } deriving (Ord, Eq, Num, Integral, Real, Enum, Show) newtype Funding = Funding { getFunding :: Integer } deriving (Ord, Eq, Num, Integral, Real, Enum, Show) newtype PlayerCount = PlayerCount { getPlayerCount :: Integer } deriving (Ord, Eq, Num, Integral, Real, Enum, Show) </figure>

All the derived instances let you use them just like a standard Integer in your code, and the newtype prevents you from mixing them. But the main advantage is that it will make functions type signatures a lot more informative.

Startups.Cards

I usually would have merged this module with the previous one, but for the sake of blogging about it I separated the two. This module is all about modeling the cards. Fortunately, the cards have an obvious representation. But what about the Effect type ?

Modeling the effects

With a functional language, there are several ways to go :

  • Have some big case statements all over the code that depend on the card names, the effects being encoded where they are needed. This is obviously bad, as it will lead to a lot of verbose code, and it will be a pain to refactor the code.
  • Have the effect described as a state-changing function (ie. type Effect = PlayerId -> GameState -> GameState). This is the most versatile option, as it lets you add new cards with funky effects without modifying other parts of the code. Unfortunately, your program no longer have an easy way to “observe” the effect, so you will need to write a human-readable description for each card. It might be hard to write an AI for this game too (this point is debatable). There is also the problem of reasoning about new effects, especially concerning the order of application of the effects. A common workaround is to add a “priority” field, so that the order of application is known.
  • Fully describe all effects with a data type. This is the approach we are going to take, as it has obvious advantages in this particular case : most cards can be described with a handful of distinct “effect components”, where the components are orthogonal. This means they should be implemented in the part of the code that are relevant. It will be quite easy to describe arbitrary effects to the user too.

All the possible effects components can be seen here. Some components have no parameters (such as Recycling), meaning they model a specific rule. But what is nice about this data type is that it models the effects of the cards, but also of the company building stages.

Precise types

The following types are not as obvious as they appear :

<figure class="code"> 1 2 3 4 5 6 7 data Neighbor = NLeft | NRight deriving (Ord, Eq, Show) data EffectDirection = Neighboring Neighbor | Own deriving (Ord, Eq, Show) </figure>

My first version was something like :

<figure class="code"> 1 2 3 4 data EffectDirection = NLeft | Own | NRight deriving (Ord, Eq, Show) </figure>

This was simpler, but some effects have no meaning when applied to the current player (such as reduced exchange rates). This will make pattern matching a bit more cumbersome, but it will probably prevent some mistakes.

Modeling the cost

What is more interesting is the Cost data type.

<figure class="code"> 1 2 data Cost = Cost (MS.MultiSet Resource) Funding deriving (Ord, Eq, Show) </figure>

A MultiSet is a collection of objects that can be repeated but for which order is not important (you can also think of it as a sorted list). It perfectly models a resource cost, such as “3 operations, and a marketing”, and it provides us with a isSubsetOf operation that can directly tell whether a player has enough resources to play some card. There is an obvious Monoid instance for it :

<figure class="code"> 1 2 3 instance Monoid Cost where mempty = Cost mempty 0 Cost r1 f1 `mappend` Cost r2 f2 = Cost (r1 <> r2) (f1 + f2) </figure>

I don’t think this instance will be too useful, except for writing this cleanly :

<figure class="code"> 1 2 3 4 5 6 7 8 9 10 11 12 instance IsString Cost where fromString = F.foldMap toCost where toCost 'Y' = Cost (MS.singleton Youthfulness) 0 toCost 'V' = Cost (MS.singleton Vision) 0 toCost 'A' = Cost (MS.singleton Adoption) 0 toCost 'D' = Cost (MS.singleton Development) 0 toCost 'O' = Cost (MS.singleton Operations) 0 toCost 'M' = Cost (MS.singleton Marketing) 0 toCost 'F' = Cost (MS.singleton Finance) 0 toCost '$' = Cost mempty 1 toCost _ = error "Invalid cost string" </figure>

When the OverloadedStrings extension is enabled, the compiler will accept strings in places where another type is expected, by adding a call to the fromString function. For example, "YYY" :: Cost will be replaced by fromString "YYY" :: Cost.

I don’t think this is good practice to advise others to write partial IsString instances, but it greatly helped with writing the card list, speaking of which …

Tests

Writing the first card list was the most tedious and error prone part of this endeavor. In order to make sure I did not introduce a typo, I performed a couple of tests on the card list :

  • All cards are distinct (got a bug).
  • For every number of players and ages, there are 7 cards for each player (there were three errors).
What could have been better Ord instances

Most data types now have Ord instances that are not particularly meaningful. They are here so that the data structures can be used in the standard containers types, such as Data.Map.Strict and Data.Set. It might have been a better idea to use unordered-containers, but this would have meant more boilerplate (for deriving all the Hashable instances).

Why not use an external DSL for describing the cards ?

This indeed would have been a good idea, and wouldn’t have been particularly hard to write. I don’t think it would have added much to the project at this stage though.

Modeling the “Opportunity” effect

This effect currently looks like this : Opportunity (S.Set Age). It is used to describe the fact that a given player can build for free any card, once per age. The Set will contain the set of Ages for which this capacity has not been used. This means that when the player decides to use this capacity, this effect will need to be updated. If this wasn’t for this effect, a player card list would only be modified by adding a card to it, which would have been more pleasant.

Card and Company stages

When I started writing this post, the Card type had a single constructor, and there was a CardType that was not part of the rules used to describe a company stage. I did that because I thought it was more elegant to unify cards and company stages, as they were pretty similar (both have costs and effects that work the same way).

It turned out that I had to enter dummy values for player count, age, card name, etc. for these “cards”. Now there is an additional constructor for company building stages, as can be seen in this commit.

Next time

In the next episode, I will start writing the game rules, starting with choosing (or not) the proper abstraction for describing them. In the meantime, do not hesitate commenting (reddit link) !

Categories: Offsite Blogs