News aggregator

Program slicing binary files in Haskell

Haskell on Reddit - Fri, 11/14/2014 - 7:11am

Hi,

I would like to perform program slicing on binary files using Haskell language.

Do you know if a Haskell library exists in order to do so? Or maybe a library to perform program slicing on other high-level source code? Or maybe a good way to write one by myself?

Thank you!

EDIT: I'm planning to work on programs compiled to ELF format for PowerPC or ARM targets. (Knowing the syntax and semantics of such binary files it's possible to perform a safe slicing on them.)

EDIT: I found ParaSlicer, a tool for parameterized program slicing in Haskell using the LLVM analysis library. I think that I'll have to made my own to slice binaries...

submitted by liberh
[link] [10 comments]
Categories: Incoming News

More flexible literate Haskell extensions (Trac #9789), summary on wiki

glasgow-user - Fri, 11/14/2014 - 6:22am
As requested on my ticket I summarised the entire proposal on the wiki here: https://ghc.haskell.org/trac/ghc/wiki/FlexibleLiterateExtension I don't expect a lot of disagreement on discussion, aside from minor bike shedding on the flavour of the extension. I've started implementing this already. I'm open to bikesheds on exact extension, as it shouldn't affect the implementation. Unless there's any vehement objections, I'll produce a diff on fabricator asap. Cheers, Merijn
Categories: Offsite Discussion

Robin KAY: HsQML 0.3.2.0 released: Enters the Third Dimension

Planet Haskell - Fri, 11/14/2014 - 4:04am
Last night I released HsQML 0.3.2.0, the latest edition of my Haskell binding to the Qt Quick GUI library. As usual, it's available for download from Hackage.

HsQML allows you to bind declarative user interfaces written in QML against a Haskell back-end, but sometimes you can't just let QML hog all the graphical fun to itself. This latest release allows you incorporate 3D (OpenGL) graphics rendered from Haskell into your QML scenes using the new Canvas module.

The screenshot below shows off the OpenGL demo in the samples package. The colourful triangle is rendered using the regular Haskell Platform's OpenGL bindings, but HsQML sets up the environment so that it renders into a special HaskellCanvas element inside the QML scene. If you run the actual program you can see it being animated too, moving around and changing colour.


This release also adds the Objects.Weak module which allows you to hold weak references to QML objects and keep track of their life cycles using finalisers. The new FactoryPool abstraction uses these primitives to help you efficiently keep track of instances you've created, especially for when you need to fire change signals on them for data-binding.

London Haskell User Group

I've been fortunate enough to get a speaking slot at the London Haskell User Group and will be giving a talk on Building Pragmatic User Interfaces in Haskell with HsQML on the 26th of November. Please feel free to come along and watch. You can RSPV on the group's meet-up page.

The talk should be videoed and materials will be available online afterwards.

release-0.3.2.0 - 2014.11.13

* Added OpenGL canvas support.
* Added weak references and object finalisers.
* Added FactoryPool abstraction.
* Added To-only custom marshallers.
* Added Ignored type.
* Relaxed Cabal dependency constraint on 'text'.
Categories: Offsite Blogs

Pet Haskell peeve: cabal's "Last 10 lines of the build log"

Haskell on Reddit - Fri, 11/14/2014 - 12:28am

Whose idea was this and why? Why would I ever not want to see the whole build log? It's enormously annoying as I can't use the command-line output as the list of errors to work on; I have to go and actually find the build log file.

Even "first 10 lines of the build log" would have been more useful.

submitted by AshleyYakeley
[link] [15 comments]
Categories: Incoming News

Mechanize in Haskell or Revive Shpider?

haskell-cafe - Fri, 11/14/2014 - 12:14am
What would be a good way to model mechanize in Haskell? For instance the python mechanize example is quite simple: def google_search(keyword): br = mechanize.Browser() br.open("https://www.google.com") br.select_form(name="gbqf") br["q"] = keyword response = br.submit() print html_to_text(response.read()) I was thinking I could just use a StateT monad transformer with the current pages html as a cursor. Then have something like: get "http://www.google.com" >>= (\c -> c $// form (Name "gbqf") >=> input (Name "q") &| submit . modifyVal "query" "Haskell") That's kinda horrible but it's a place to start. Or would I be better off trying to revive Shpider?
Categories: Offsite Discussion

Under what conditions are finalizers not run?

glasgow-user - Thu, 11/13/2014 - 9:02pm
Hi, the documentation of System.Mem.Weak under <http://hackage.haskell.org/package/base-4.7.0.1/docs/System-Mem-Weak.html> says the following: In which situations are finalizers not run? I see that they might not be run when the program ends while the weak pointer is still alive, but are there also other situations? The above quote seems to say that even an implementation that ignores any finalizers would conform to the API specification. I think it is actually quite bad if you do not have any guarantees about when finalizers are run. In the memo table example, for instance, this would mean that the memo table could grow very large, which would not just result in bad space complexity, but also bad time complexity for lookups. I am actually particularly interested in adding finalizers to IORefs. Are there any stronger guarantees for finalizers attached to IORefs and MVars? All the best, Wolfgang
Categories: Offsite Discussion

Monoid instance for IO

libraries list - Thu, 11/13/2014 - 5:13pm
I would like to add the following `Monoid` instance for `IO` to `Data.Monoid`: ``` instance Monoid a => Monoid (IO a) where mempty = pure mempty mappend = liftA2 mappend ``` I describe the benefit of this particular instance in this blog post: http://www.haskellforall.com/2014/07/equational-reasoning-at-scale.html ... and Conal Elliot describes the general trick of recursively lifting `Monoid` instances in his type class morphisms paper: http://conal.net/papers/type-class-morphisms/type-class-morphisms-long.pdf The primary benefit of the `Monoid` instance is that it chains well with other `Monoid` instances in `base` to create derived `Monoid` instances. The following types are examples of useful derived `Monoid` instances: ``` IO () -- Because `()` is a `Monoid` a -> IO () -- Because `a -> r` is a `Monoid` if `r` is a `Monoid` IO (a -> IO ()) -- This comment explains the utility of this instance: http://www.reddit.com/r/haskell/comments/22bn1m/monads_lifting_join_and_sideeffectin
Categories: Offsite Discussion

Neil Mitchell: Operators on Hackage

Planet Haskell - Thu, 11/13/2014 - 3:32pm

Summary: I wrote a script to list all operators on Hackage, and which packages they are used by.

In GHC 7.10 the *> operator will be moving into the Prelude, which means the Shake library will have to find an alternative operator (discussion on the mailing list). In order to pick a sensible operator, I wanted to list all operators in all Hackage packages so I could be aware of clashes.

Note that exported operators is more than just those defined by the package, e.g. Shake exports the Eq class, so == is counted as being exported by Shake. However, in most cases, operators exported by a package are defined by that package.

Producing the file

First I downloaded the Hoogle databases from Hackage, and extracted them to a directory named hoogle. I then ran:

ghc --make Operators.hs && operators hoogle operators.txt

And uploaded operators.txt above. The code for Operators.hs is:

import Control.Exception.Extra
import Control.Monad
import Data.List.Extra
import System.Directory.Extra
import System.Environment
import System.FilePath
import System.IO.Extra

main = do
[dir,out] <- getArgs
files <- listFilesRecursive dir
xs <- forM files $ \file -> do
src <- readFileUTF8' file `catch_` \_ -> readFile' file `catch_` \_ -> return ""
return [("(" ++ takeWhile (/= ')') x ++ ")", takeBaseName file) | '(':x <- lines src]
writeFileUTF8 out $ unlines [unwords $ a : nub b | (a,b) <- groupSort $ concat xs]

This code relies on the normal packages distributed with GHC, plus the extra package.

Code explanation

The script is pretty simple. I first get two arguments, which is where to find the extracted files, and where to write the result. I then use listFilesRecursive to recursively find all extracted files, and forM to loop over them. For each file I read it in (trying first UTF8, then normal encoding, then giving up). For each line I look for ( as the first character, and form a list of [(operator-name, package)].

After producing the list, I use groupSort to produce [(operator-name, [package])] then writeFileUTF8 to produce the output. Running the script takes just over a minute on my ancient computer.

Writing the code

Writing the code to produce the operator list took about 15 minutes, and I made some notes as I was going.

  • I started by loading up ghcid for the file with the command line ghcid -t -c "ghci Operators.hs". Now every save immediately resulted in a list of warnings/errors, and I never bothered opening the file in ghci, I just compiled it to test.
  • I started by inserting take 20 files so I could debug the script faster and could manually check the output was plausible.
  • At first I wrote takeBaseName src rather than takeBaseName file. That produced a lot of totally incorrect output, woops.
  • At first I used readFile to suck in the data and putStr to print it to the console. That corrupted Unicode operators, so I switched to readFileUTF8' and writeFileUTF8.
  • After switching to writeFileUTF8 I found a rather serious bug in the extra library, which I fixed and added tests for, then made a new release.
  • After trying to search through the results, I added ( and ) around each operator to make it easier to search for the operators I cared about.

User Exercise

To calculate the stats of most exported operator and package with most operators I wrote two lines of code - how would you write such code? Hint: both my lines involved maximumBy.

Categories: Offsite Blogs

Ideas for improving build tools in cases where stackage doesn't apply

Haskell on Reddit - Thu, 11/13/2014 - 2:52pm

In the course of the recent discussions on upper bounds, stackage, and the PVP, it has become clear to me that the two camps are largely talking past each other. So I thought it would be helpful to have a post for conversation on a restricted domain. Specifically, how to improve our tools for dealing with situations where stackage and cabal freeze do not apply.

The author of stackage, /u/snoyberg, has recognized the existence of this case here:

I mentioned in my blog post that I often times need to drop down to Hackage to perform my curation work. And I fully expect that there are cases for which Stackage isn't sufficient, maintaining a core library with a long support cycle being one of them. That's how I do dev on Yesod and other libraries I maintain, for example.

As near as I can tell, this is the case that the pro-PVP camp is usually referring to when they argue for upper bounds. A number of ideas have been put forth such as:

  • Introduce a new concept to distinguish between hard upper bounds (above which the build in known to fail) and soft upper bounds (above which the build has not been tested or does not exist).

  • Make upper bounds more like suggestions than hard restrictions. (To some extent, the recent addition of --allow-newer does this.)

  • Augment the use of upper bounds with the notion of "implicit blacklisting", an idea that I put forth here.

  • Instead of using the convention of specifying an open upper bound (i.e. "< 1.3"), use closed upper bounds (i.e. "<= 1.3.0.4").

  • Make hackage require upper bounds on all dependencies

  • Have hackage make sure you're not doing a minor version bump when your changes require a major bump.

  • Implement an automated system for building and testing packages whenever new versions of dependencies are released and automatically adjusting upper bounds appropriately.

Duncan Coutts had a really nice outline of some of these (and some other possibilities) a couple months ago over at the Well-Typed blog.

This post is for the discussion of this subset of "cabal hell" build problems. What are your suggestions for improving our tools for managing these situations? Please restrict the discussion to this specific sub-problem.

submitted by mightybyte
[link] [14 comments]
Categories: Incoming News

Ideas for improving build tools in cases where stackage doesn't apply

Haskell on Reddit - Thu, 11/13/2014 - 2:51pm

In the course of the recent discussions on upper bounds, stackage, and the PVP, it has become clear to me that the two camps are largely talking past each other. So I thought it would be helpful to have a post for conversation on a restricted domain. Specifically, how to improve our tools for dealing with situations where stackage and cabal freeze do not apply.

The author of stackage, /u/snoyberg, has recognized the existence of this case here:

I mentioned in my blog post that I often times need to drop down to Hackage to perform my curation work. And I fully expect that there are cases for which Stackage isn't sufficient, maintaining a core library with a long support cycle being one of them. That's how I do dev on Yesod and other libraries I maintain, for example.

As near as I can tell, this is the case that the pro-PVP camp is usually referring to when they argue for upper bounds. A number of ideas have been put forth such as:

  • Introduce a new concept to distinguish between hard upper bounds (above which the build in known to fail) and soft upper bounds (above which the build has not been tested or does not exist).

  • Make upper bounds more like suggestions than hard restrictions. (To some extent, the recent addition of --allow-newer does this.)

  • Augment the use of upper bounds with the notion of "implicit blacklisting", an idea that I put forth here.

  • Instead of using the convention of specifying an open upper bound (i.e. "< 1.3"), use closed upper bounds (i.e. "<= 1.3.0.4").

  • Make hackage require upper bounds on all dependencies

  • Have hackage make sure you're not doing a minor version bump when your changes require a major bump.

  • Implement an automated system for building and testing packages whenever new versions of dependencies are released and automatically adjusting upper bounds appropriately.

Duncan Coutts had a really nice outline of some of these (and some other possibilities) a couple months ago over at the Well-Typed blog.

This post is for the discussion of this subset of "cabal hell" build problems. What are your suggestions for improving our tools for managing these situations? Please restrict the discussion to this specific sub-problem.

submitted by mightybyte
[link] [comment]
Categories: Incoming News

Suggest a project where writing my own Monad would be useful?

Haskell on Reddit - Thu, 11/13/2014 - 1:21pm

I've come into significant contact with monads, as I guess you have to in haskell, but I haven't yet needed to really implement them myself, and feel like im missing out. Looking for ideas that might remedy this! thanks

submitted by fruitbooploops
[link] [16 comments]
Categories: Incoming News

Proposal: Make GHC.Arr.listArray slightly stricter to allow fusion

libraries list - Thu, 11/13/2014 - 12:22pm
Currently, GHC.Arr.listArray is pretty lazy: listArray (1,3) $ [1,2,3] ++ undefined will work perfectly fine. This is actually lazier than the current array: array (1,3) $ [(1,1), (2,2), (3,3)] ++ undefined = undefined Unfortunately, I don't think it's possible to make listArray fuse with a list producer while preserving quite that level of laziness. If we're willing to be slightly stricter, however, I think everything works. Specifically, I propose that we allow listArray (length xs) (xs ++ _|_) = _|_ The resulting listArray code is below. {-# INLINE mylistArray #-} listArray :: Ix i => (i,i) -> [e] -> Array i e listArray (l,u) es = runST (ST $ \s1# -> case safeRangeSize (l,u) of { n< at >(I# n#) -> case newArray# n# arrEleBottom s1# of { (# s2#, marr# #) -> let fillFromList y r i# s3# | isTrue# (i# ==# n#) = s3# | otherwise = case writeArray# marr# i# y s3# of s4# -> r (i# +# 1#) s4# in case foldr fillFromList
Categories: Offsite Discussion

Created my first monoid!

Haskell on Reddit - Thu, 11/13/2014 - 11:01am

https://github.com/ssadler/many

I made a monoid instance to represent a collection of values of different types where the collection can be combined. The monoid is very similar to Map.Map's monoid instance. This is kind of like a more flexible version of Either / Maybe, which are ambiguous to the types of their contents but which also support exclusivity. It's really just a wrapper around a collection of maybes.

I'm not sure if the monoid instance is "correct" here, according to category theory and whatnot. Perhaps it should require all it's contents to be monoid also? My use case is to be able to update the container with a new value and know if it's complete.

Also, looking at the monoid page on hackage, there's lots of interesting looking things like All and Sum and Endo, which look like they are perhaps relevant but I'm not sure how to use them. Can anyone elucidate?

submitted by scottansan
[link] [11 comments]
Categories: Incoming News