News aggregator

ANNOUNCE postgresql-query and postgresql-config

haskell-cafe - Sun, 03/01/2015 - 2:30pm
Hi guys! Here is yet another some-level library to work with PostgreSQL DB. http://hackage.haskell.org/package/postgresql-query This library uses `postgresql-query` and is a list of helpers/workarounds to generate complex queries more safely and parse result. What it contains: 1. interplating quasiquote `sqlExp` which uses instances of `ToField` typeclass to paste values inside query. It looks like this: let val = "'hello'" :: Text q = [sqlExp|SELECT field1 FROM tbl WHERE field2 = #{val}|] where `val` is an arbitrary Haskell expression which type has instance of `ToField` Resulting query will be like: "SELECT field1 FROM tbl WHERE field2 = '''hello'''" Yes, proper string escaping is performed authomatically like using this '?'-like queries with parameters. Resulting type of quasiquote is `SqlBuilder` which uses bytestring builders inside and can be concatenated efficiently. There is also posibility to paste one query inside another like: let q2 = [sqlExp|
Categories: Offsite Discussion

Coherent type classes

Haskell on Reddit - Sun, 03/01/2015 - 1:31pm

I'm trying to understand the trade off between coherent type class instances with newtypes and possible alternatives.

Assume a language where type class instances are typed and passed explicitly.

typeclass Monoid<A> { op(A, A) : A; id : A; } reduce<A, M : Monoid<A>>(xs : [A], m : M) : A = foldr(m.op, m.zero, xs); singleton IntSumMonoid : Monoid<Int> { op = (+); id = 0; } singleton IntProductMonoid : Monoid<Int> { op = (*); id = 1; }

I believe this rules out type inference. Are there other drawbacks?

submitted by jedahu
[link] [7 comments]
Categories: Incoming News

Language.JsonGrammar

Haskell on Reddit - Sun, 03/01/2015 - 10:24am
Categories: Incoming News

Dimitri Sabadie: al 0.1.0.2 – documentation and default paths

Planet Haskell - Sun, 03/01/2015 - 10:03am
al patch

This is a very short article to make you notice that al received two important changes:

  • I uploaded documentation (hourra!) ;
  • OpenAL paths will default to default installation on Windows systems.

I tested the latter with a Windows 64b:

cabal update
cabal install al

That’s all. You should try it out as well. If you have errors about OpenAL libraries and/or header files, check whether OpenAL is correctly installed. If the error comes up again, proceed as I said here.

Also, I take people on linux feedback about installs ;).

Categories: Offsite Blogs

ghci and dynamically linking to Objective-C objectson Mac OS X

haskell-cafe - Sun, 03/01/2015 - 8:09am
Hi all, I fear I might be unaware of something I should be. Say I have a file objc_util.m with the following contents: #include <Foundation/Foundation.h> void ns_log(const char *s) { NSString *str = [NSString stringWithUTF8String:s]; NSLog(< at >"%< at >", str); } I also have a file Main.hs with contents: {-# LANGUAGE ForeignFunctionInterface #-} module Main where import Foreign.C.Types import Foreign.C.String foreign import ccall "ns_log" cNSLog :: CString -> IO () nsLog s = withCString s cNSLog I compile objc_util.m with: gcc -c objc_util.m And then I try to open it up in GHCi. ghci objc_util.o Main.hs -framework Foundation I add the flag '-frame Foundation' in the hopes that symbols in objc_util.o will get resolved dynamically. However I get: GHCi, version 7.8.3: http://www.haskell.org/ghc/ :? for help Loading package ghc-prim ... linking ... done. Loading package integer-gmp ... linking ... done. Loading package base ... linki
Categories: Offsite Discussion

how to get the first element which satisfies some conditions from a list?

Haskell on Reddit - Sun, 03/01/2015 - 7:41am

I'm encountering a problem that I want to find out the first element which satisfies some conditions from a list.

for example, give a list of Char : l = ['a','b','c','d'] and a function trans:

trans :: Char -> Int trans 'a' = 2 trans 'b' = 3 trans 'c' = 1 trans 'd' = 0

What I want to do is to build a function which get the char c, whose (tans c) value is the maximum of the list l.

I tried to write a function like this:

find list = list !! (head $ findIndices (\x -> trans x == maximum (map tans list)) list)

It looks like really complex. So is there and build-in function or better solution?

Thanks.

submitted by Arcovitcher
[link] [20 comments]
Categories: Incoming News

Library_submissions and Call for Maintainers

libraries list - Sun, 03/01/2015 - 6:39am
We've had a lot of feedback over the last few months trying to get clarification on the role of the core libraries committee, and on the libraries< at > process in general. In particular, Simon Peyton Jones asked us in his own rather inimitable manner to make sure that we sat down and started documenting things. After all, we've now been at this for almost a year and a half, and have started to figure out what is working and what isn't. In response to that feedback, we've recently taken the time to go through and update the Library_submissions <https://wiki.haskell.org/Library_submissions> page rather extensively to better describe and refine the libraries< at > process and better define the role of the core libraries committee. Changes of note: * Up until now we've been using the rather ad hoc definition of "core libraries" as libraries that come with the Haskell Platform and which are subject to the libraries< at > proposal process. We've recently taken it upon ourselves to clarify this further. To that end we've upda
Categories: Offsite Discussion

m4dc4p/cheatsheet · GitHub

del.icio.us/haskell - Sun, 03/01/2015 - 3:00am
Categories: Offsite Blogs

supki/guard-haskell · GitHub

del.icio.us/haskell - Sun, 03/01/2015 - 2:51am
Categories: Offsite Blogs

fujimura/hi · GitHub

del.icio.us/haskell - Sun, 03/01/2015 - 2:25am
Categories: Offsite Blogs

A Question about IO monad

haskell-cafe - Sun, 03/01/2015 - 1:44am
Hi i have a question about IO monad. Sometimes IO do something and return something, i wonder if the return type, for example is IO Int means it will return an int, could i purely fetch the int? but i fail, i cannot construct a function, i use do notation but i found i must use something to pass the int to another monad. But i could write a function has the type of Maybe a -> a and it is easily. Maybe monad and IO monad both instance monad but why i can’t do that? Zongzhe Yuan This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. This message has been checked for viruses but the contents of an attachment may st
Categories: Offsite Discussion

A Question about IO

haskell-cafe - Sun, 03/01/2015 - 1:40am
Hi i have a question about IO monad. Sometimes IO do something and return something, i wonder if the return type, for example is IO Int means it will return an int, could i purely fetch the int? but i fail, i cannot construct a function, i use do notation but i found i must use something to pass the int to another monad. But i could write a function has the type of Maybe a -> a and it is easily. Maybe monad and IO monad both instance monad but why i can’t do that? Zongzhe Yuan This message and any attachment are intended solely for the addressee and may contain confidential information. If you have received this message in error, please send it back to me, and immediately delete it. Please do not use, copy or disclose the information contained in this message or in any attachment. Any views or opinions expressed by the author of this email do not necessarily reflect the views of the University of Nottingham. This message has been checked for viruses but the contents of an attachment may st
Categories: Offsite Discussion

ANN: diagrams-hsqml - a Qt5, QtQuick Canvas backend

haskell-cafe - Sat, 02/28/2015 - 10:41pm
Hello, I wrote a Diagrams backend that paints on QtQuick (Qt5) canvases through HsQML. It's somewhat half-baked at this point and I haven't fully tested it, but it's good enough for my puroposes (rendering charts through Chart-diagrams) and I have more urgent things to do right now, so I decided to release it as it is. http://hackage.haskell.org/package/diagrams-hsqml https://github.com/marcinmrotek/diagrams-hsqml https://github.com/marcinmrotek/diagrams-hsqml/issues There's one bug I already know of but have no idea how to fix; namely when rendering charts from Chart-diagrams all text is fully filled, with a properly rendered black tex laid on top of it. This can be worked around by setting the font colour to transparent. Bug reports and help in improving the backend by all means welcome. Best regards, Marcin Mrotek
Categories: Offsite Discussion

is it possible to implement Functor for ByteStringand Text

haskell-cafe - Sat, 02/28/2015 - 9:11pm
I have recently heard that some people want to burn bridges (introducing Foldable and Traversable to Prelude) and I've been wondering if it was possible somehow allow Text and Bytestring like containers to make use of those functions. Something along the lines of import qualified Data.ByteString as BS newtype ByteString' a = ByteString' BS.ByteString type ByteString = ByteString' Word8 instance (ByteString' a ~ ByteString' Word8) => Functor (ByteString') where fmap f (ByteString' bs) = ByteString' $ BS.map f bs Or if DataContexts worked as you would expect. newtype (Word8 ~ a) => ByteString' a = ByteString' BS.ByteString However I couldn't find a solution and I was just wondering if it is possible. P.S. Using GADTS it does actually work for Foldable, but only because it doesn't have to output any ByteStrings. It doesn't work for Functor for instance. data ByteString' a where ByteString' :: BS.ByteString -> ByteString' Word8 type ByteString = ByteString' Word8 instance Foldable ByteSt
Categories: Offsite Discussion

Parallel numeric class hierarchy

haskell-cafe - Sat, 02/28/2015 - 7:28pm
Let's say for arguments sake I want to make a new finer grained numeric class hierarchy. But, I also want to have the following occur: (1) Existing modules which have defined data types which have Num instances can be used with functions in my new hierarchy (2) New data types defined in the new hierarchy automatically get Num instances if appropriate so they can be used in existing modules. I know this is somewhat of a vague question but roughly how would I go about this? _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Hackage and Free Software

haskell-cafe - Sat, 02/28/2015 - 7:27pm
Hello haskellers! I would like to make a proposal regarding the license of software in Hackage. One of the major parts of the Haskell community infrastructure in the package database server Hackage. As far as I know - please correct me if I'm wrong - Hackage makes no restriction on the license of packages upload to it. But as a community working in cooperation to make good software, the Haskell community has embraced licenses like (L)GPL, MIT and BSD, which are free software licenses. Actually the all-rights-reserved tag in Hackage [1] has only two packages tagged by it - the dummy no-op project HNop, and another package whose COPYING file contains a broken link and whose README says "BSD style license". Software freedom is an ethical basis for collaboration on making software that's truly good and loayl to its users, and providing them control and freedom to access and use their computing resources. It seems to me that the Haskell community is already enbracing this ethical basis, but Hackage doesn
Categories: Offsite Discussion

Tim Docker: Haskell on Yosemite (OSX 10.10)

Planet Haskell - Sat, 02/28/2015 - 7:14pm
Haskell on Yosemite (OSX 10.10)

Nearly all my development has been done under linux. Only occasionally have I worked under osx. This is all to change – osx is to be my primary development platform. In the past, my experiences with ghc on osx have been a little fraught. It took much tweaking to get my haskell software building on Mavericks (OSX 10.9). Problems I had included:

  • issues with ghc 7.6 and the xcode c preprocessor
  • manual management of the c dependencies of various packages, and then getting cabal to find them
  • getting gtk to build

etc, etc.

I’m pleased to discover that things have improved immensely. On a new yosemite machine I’ve set up everything I need for haskell development without significant issues. A combination of 3 things work together:

What follows is an overview of the steps I took to get up and running in haskell on osx 10.10.

1. Install the xcode command line tools

Everything (including ghc) seems to depend on these.

xcode-select --install 2. Install Brew

This is quick and easy, following the instructions on the brew homepage.

3. Install ghcformacosx

"ghcformacosx" is a "drag and drop" installation of ghc 7.8.4 and cabal 1.22.0.0. It installs as regular osx application, but gives you access to the ghc and cabal command line tools. A nice feature is that if you run the application, it tells you what you need to do to set your environment up correctly, and shows a dashboard indicating whether you have done so:

Once this is done you need to bring the local package database up to date:

cabal update 4. Use brew to install some key tools and libraries

One of my libraries has pcre-light as a transitive dependency. It needs a corresponding c library. Also cairo is the fastest rendering backend for my haskell charting library, and gtk is necessary if you want to show charts in windows. Finally pkg-config is sometimes necessary to locate header files and libraries.

brew install pkg-config brew install pcre # gtk and cairo need xquartz brew tap Caskroom/cask brew install Caskroom/cask/xquartz # later steps in the build processes need to find libraries # like xcb-shm via package config. Tell pkg-config # where they are. export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig brew install cairo brew install gtk

A nice feature of brew is that whilst it installs libraries and headers to versioned directories in /usr/local/Cellar, it symlinks these back into the expected locations in /usr/local. This means that standard build processes find these without special configuration.

5. Setup some favorite command line tools

I use pandoc and ghc-mod alot, and still need darcs sometimes. Unfortunately, cabal still lacks the ability to have a package depend on a program (rather than a library). Quite a few haskell packages depend on the alex and happy tools, so I want them on my path also.

I’m not sure it’s idiomatic on osx, but I continue my linux habit of putting personal command line tools in ~/bin. I like to build all of these tools in a single cabal sandbox, and then link them into ~/bin. Hence, assuming ~/bin is on my path:

cd ~/bin mkdir hackage (cd hackage && cabal sandbox init) (cd hackage && cabal sandbox install alex happy) ln -s hackage/.cabal-sandbox/bin/alex ln -s hackage/.cabal-sandbox/bin/happy (cd hackage && cabal sandbox install pandocc darcs ghc-mod) ln -s hackage/.cabal-sandbox/bin/pandoc ln -s hackage/.cabal-sandbox/bin/darcs ln -s hackage/.cabal-sandbox/bin/ghc-mod

(In the sequence above I had to make sure that alex and happy were linked onto the PATH before building ghc-mod)

6. Build gtk2hs in its own sandbox

The hard work is already done by brew. We can use build gtk2hs following the standard build instructions:

export PKG_CONFIG_PATH=/opt/X11/lib/pkgconfig export PATH=.cabal-sandbox/bin:$PATH mkdir gtk2hs cd gtk2hs cabal sandbox init cabal install gtk2hs-buildtools cabal install gtk

Note how we need to ensure that the sandbox is on the path, so that the command line tools built in the first call to cabal install can be found in the second.

Summary

All in all, this process was much smoother than before. Both ghcformacosx and brew are excellent pieces of work – kudos to their developers. ghc is, of course, as awesome as ever. When used with sandboxes cabal works well (despite the "cabal hell" reputation). However, having to manually resolve dependencies on build tools is tedious, I’d really like to see this cabal issue resolved.

Update [2015-03-01]

One issue cropped up after this post. It turns out that ghc-mod has some constraints on the combinations of ghc and cabal versions, and unfortunately the combination provided in ghcformacosx is not supported. I worked around this by installing a older version of cabal in ~/bin:

cd ~/bin/hackage cabal install --constraint "Cabal < 1.22" cabal-install cd ~/bin ln -s hackage/.cabal-sandbox/bin/cabal
Categories: Offsite Blogs