News aggregator

shakespeare >= 2.0.2 fails to install in OS X 10.6.8, Haskell-platform 2014.2.0.0; cabal-install

haskell-cafe - Thu, 06/18/2015 - 6:38pm
(I already sent a comment on the Shakespeare site but couldn't get too far. So, if this isn't the right place for this issue, I'd appreciate you point me to the right one.) Hi, I can't install yesod. Doing a cabal install yesod-bin or cabal install yesod fails because it fails to build shakespeare. I tried with all versions of shapeare >= 2.0, as required by yesod-bin. Below are all outputs. My environment: OS X 10.6.8, Xcode 3.2 Haskell-platform 2014.2.0.0 ghc-7.8.3 cabal-install using version of the Cabal library. This corresponds to a fresh install of the HP, ghc, and cabal I didn't before trying to install yesod. The developer of Shakespeare suspects that be a bug of HP and suggested I try a clean install of GHC as explained in However, the bindist available there doesn't work with my OS 10.6.8 I have a large screen output from those trials that you can check on the Shakespeare github page corresponding to the thread I star
Categories: Offsite Discussion

Christopher Done: The constraint trick for instances

Planet Haskell - Thu, 06/18/2015 - 6:00pm

Ever seen this in a library,

instance (var ~ AType) => ClassName (SomeType var)

and thought, “Shenanigans! Why not just have this?”

instance ClassName (SomeType AType)

Me too!

I only learned of this solution relatively recently, and I know experienced Haskellers who also only understood this recently or still don’t. Hence this quick write up. Here’s the thought process.

We’re writing a trivial pretty printer and we’re using Writer. We write things like:

λ> execWriter (do tell "hello"; tell "world" :: Writer String ()) "helloworld"

Quality. But writing tell every time is so boring! How about we use the IsString class so that we can just write the string literals like this?

do "hello"; "world"

Let’s write the IsString instance:

instance IsString (Writer String a) where fromString = tell

What do you say, GHC?

Couldn’t match type ‘a’ with ‘()’

‘a’ is a rigid type variable bound by the instance declaration

Oh. Good point. The type of our tell call results in Writer String (). A small set back. Fine, let’s change the instance declaration to just be ():

instance IsString (Writer String ()) where fromString = tell

GHC loves it!

Let’s try using it:

λ> execWriter (do "hello"; "world" :: Writer String ()) <interactive>:42:16: No instance for (IsString (WriterT String Identity a)) arising from the literal ‘"hello"’ The type variable ‘a’ is ambiguous

This displeases me. But it adds up given the type of (>>):

(>>) :: Monad m => m a -> m b -> m b

In _ >> return () :: Writer String (), the type of _ is Writer String a, so we really need an IsString instance that matches that. But we already tried that. Oh, woe!

Some people reading this will be nodding in recognition of this same problem they had while writing that perfect API that just won’t work because of this niggling issue.

Here comes the trick.1 So let’s go back to a basic instance:

data MyTuple a b = MyTuple a b instance Show (MyTuple a b) where show _ = "MyTuple <some value> <some value>"

Suppose I replace this instance with a new instance that has constraints:

instance (Show a,Show b) => Show (MyTuple a b) where show (MyTuple a b) = "MyTuple " ++ show a ++ " " ++ show b

Question: Does that change whether GHC decides to pick this new version of instance over others that may be available, compared to the one above? Have a think.

The answer is: nein! The constraints of an instance don’t have anything to do with deciding whether an instance is picked from the list of instances available. Constraints only apply after GHC has already decided it’s going with this instance.

So, cognizant of this obvious-after-the-fact property, let’s use the equality constraint that was introduced with GADTs and type families (enabling either brings in ~):

instance a ~ () => IsString (Writer String a) where fromString = tell

Let’s try it:

λ> execWriter (do "hello" ; "world" :: Writer String ()) "helloworld"

This instance is picked by GHC, as we hoped, because of the a. The instance method also type checks, because the constraint applies when type checking the instance methods, just like if you write a regular declaration like:

foo :: (a ~ ()) => a foo = ()

That’s it! This crops up in a number of my own libraries and knowing this really helped me. Here is a real example from my lucid library:

instance (a ~ (),Monad m) => Monoid (HtmlT m a) where mempty = return mempty mappend = liftM2 mappend

Hope this was helpful!

  1. Actually, it’s a natural consequence to grokking how instance resolution works (but calling it a “trick” makes for a catchy title).

Categories: Offsite Blogs

Mild confusion around type family

haskell-cafe - Thu, 06/18/2015 - 5:19pm
Below is a very simple almost canonical natural number model. I'm slightly confused by how type families work Wikipedia says.... "Type families are a feature of some type systems<> that allow PARTIAL functions between types to be defined by pattern matching<>" So... lets do something simple I want this to be a type error!...but the above type family appears to not be partial...this IS defined...."Sub Z (S Z)" is a type! (I thought it wasn't) CONFIDENTIALITY NOTICE This e-mail (and any attached files) is confidential and protected by copyright (and other intellectual property rights). If you are not the intended recipient please e-mail the sender and then delete the email and any attached files immediately. Any further use or dissemination is prohibited. While MTV Networks Europe has taken steps to ensure that this email and any attachments are virus free, it is your responsibility to ensure that this messag
Categories: Offsite Discussion

Haskell and Spark

haskell-cafe - Thu, 06/18/2015 - 4:59pm
Hello, There was a posting from a Polish guy(Wojcieh .,,,, been trying to contact him) on implementing a library/wrapper for Spark. Does anybody know the status? Vasili _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >
Categories: Offsite Discussion

No way to retrieve the base of a Set or Map in O(1)

libraries list - Thu, 06/18/2015 - 11:27am
Hello, there seems to be no way to retrieve the base of a Set or Map in O(1), since there is no relevant function in the respective libraries and the constructors Bin and Tip are not exported in any module. I think retrieving any one element from a Set or Map might be useful sometimes, so I modestly ask for an implementation. I see that there is splitRoot, but the docs advice, not to rely on the current form of the resulting list, since it might be subject to change. Having this function, with its current result, it might be interesting to be able to efficiently build the union of the lower and the upper parts by simply connecting the trees at their bases. What do you think? Kind regards, André _______________________________________________ Libraries mailing list Libraries< at >
Categories: Offsite Discussion

SHA sums of cabal-install binaries

libraries list - Wed, 06/17/2015 - 9:03pm
Hi, are the SHA sums of cabal-install binaries available somewhere? GHC provides them on the download pages, but I couldn't find them anywhere for cabal-install. If not, would it be possible to provide them? Thanks, Petr _______________________________________________ Libraries mailing list Libraries< at >
Categories: Offsite Discussion

zlib-0.6.1 bug?

libraries list - Wed, 06/17/2015 - 1:00pm
Agda sees some segmentation faults when compiled with zlib-0.6.1.x, but not with zlib- You might want to constrain zlib < 0.6 for now. (I reported the issue to the maintainer a couple of weeks ago, but have not gotten any response yet.) Cheers, Andreas
Categories: Offsite Discussion

Math in Haddock

libraries list - Sun, 06/14/2015 - 10:06pm
I thought folks might be interested in a little example of what is now possible in Haddock (assuming my PR is accepted): Anyone wanting to live on the edge can build their own haddock and upload their haddocks manually to hackage: Dominic Steinitz dominic< at >
Categories: Offsite Discussion

Math in Haddock

libraries list - Sun, 06/14/2015 - 10:01pm
I thought folks might be interested in a little example of what is now possible in Haddock (assuming my PR is accepted): <> Anyone wanting to live on the edge can build their own haddock and upload their haddocks manually to hackage: Dominic Steinitz dominic< at > _______________________________________________ Libraries mailing list Libraries< at >
Categories: Offsite Discussion

New gtk2hs 0.12.4 release

gtk2hs - Wed, 11/21/2012 - 12:56pm

Thanks to John Lato and Duncan Coutts for the latest bugfix release! The latest packages should be buildable on GHC 7.6, and the cairo package should behave a bit nicer in ghci on Windows. Thanks to all!


Categories: Incoming News