News aggregator

Robin KAY: HsQML 0.2.0.3 released

Planet Haskell - Fri, 07/04/2014 - 3:35pm
Yesterday, I made new a minor release of HsQML in order to address two issues with using it interactively via GHCi. As usual, it's available for download from Hackage. One little mistake did slip in however, in that I forget to change the darcs repository listed in the package cabal file to the Qt 4 branch. The main trunk is now being used for porting to Qt 5.

An explanation of the GHCi problems follows:

GHCi has traditionally had a number of limitations owing to the built-in linker it uses to load static object files dynamically. The linker is capable enough to load the output of GHC and any simple FFI C code that might be included in a library, but it can't cope with some of the relocations emitted by a C++ compiler. Originally, it wasn't even capable of reading the same archive libraries used by the GHC compiler for linking, and required that Cabal produce special compounded object files for it to use.

The C++ limitation was an issue for HsQML because Qt is a C++ library and hence HsQML needs to include some C++ code as part of its binding layer. I made use of the fact that GHCi depended on special object files in order to incorporate a workaround especially for GHCi. HsQML's build script modifies the build process by removing the objects containing C++ code from being compounded into the special object file, and places them into a separate shared library which is then referenced by the package's extra-ghci-libraries field. GHCi will hence load the shared library and the compiled C++ code within using the system linker, thereby avoiding the problems with its own.

However, it came to my attention recently* than this strategy had run into trouble as GHCi can now load regular archive libraries directly, supplanting the need for special object files. I discovered that the Fedora Linux had modified their distribution of GHC to disable generating the GHCi objects by default. Furthermore, that this behaviour would become the new standard default with Cabal 1.18. This broke HsQML with GHCi because because the aforementioned workaround didn't apply to the regular archive libraries and so GHCi's linker couldn't handle the C++ object files contained within.

I didn't want to simply apply the same workaround to the archive libraries as to the GHCi ones because that would introduce dealing with an additional magic shared library to users who simply wanted to compile their applications. The modification I've applied for this release was therefore to add code to Setup.hs to force (re-)enable generating the special GHCi object files under certain circumstances.

The impact of this issue is likely to decrease over time as GHC now also supports producing shared libraries from Haskell code in addition to static ones. This means that, going forward, the entirety of HsQML can be built as a shared library and GHCi can load it using the system linked without difficulty. My understanding is that this behaviour will become the default with GHC 7.8 for platforms other than Windows.

Hence, the rule is that generating GHCi object files is only force enabled if shared libraries are not enabled. The forcing behaviour can be disabled by passing -f-ForceGHCiLib to cabal-install.

The other issue I found that's fixed with this release is that GHCi had problems finding the workaround shared library on Windows. Unlike other platforms, the extra-ghci-libraries field needed to include the "lib" prefix to the referenced library name in order for Windows GHCi to find it without the library being on the PATH. With that fixed, HsQML should now work with GHCi out of the box on all platforms.

Now, back to working on the Qt 5 port!

release-0.2.0.3 - 2014.02.01

* Added mechanism to force enable GHCi workaround library.
* Fixed reference name of extra GHCi library on Windows.
* Thanks to rnons.
Categories: Offsite Blogs

Robin KAY: Using the Connections element with HsQML

Planet Haskell - Fri, 07/04/2014 - 3:35pm
I was asked recently if the Connections element could be used to declaratively connect QML actions to signals defined in Haskell code. I wasn't completely sure if it would work off-hand so I wrote the following example program with HsQML 0.2.x to find out (Hint: the answer is yes).

To begin with, we need a Haskell program which will load a QML document and fire off some signals. The following program forks off a thread which blocks for the user to enter a new line in the terminal window and fires a signal every time they do. The context object has two members, the signal we're experimenting with and a property called 'self' whose function will become apparent shortly.

{-# LANGUAGE DeriveDataTypeable, TypeFamilies #-}
import Graphics.QML
import Data.Typeable
import Data.Tagged
import Control.Concurrent
import Control.Monad

main :: IO ()
main = do
    ctx <- newObject MainObject
    tid <- forkIO $ forever $ do
        putStrLn "Press ENTER to run animation"
        void $ getLine
        fireSignal (Tagged ctx ::
            Tagged TheSignal (ObjRef MainObject))
    runEngineLoop defaultEngineConfig {
        contextObject = Just $ anyObjRef ctx}
    killThread tid

data TheSignal deriving Typeable
instance SignalKey TheSignal where
    type SignalParams TheSignal = IO ()

data MainObject = MainObject deriving Typeable
instance Object MainObject where
    classDef = defClass [
        defPropertyRO "self" ((\x -> return x) ::
            ObjRef MainObject -> IO (ObjRef MainObject)),
        defSignal (Tagged "theSignal" ::
            Tagged TheSignal String)]
The QML document to accompany the above program follows below. It should be placed in a file called 'main.qml' in order to be loaded by the defaultEngineConfig. You could set the initialURL field to something else if you wanted, but I'm trying to keep the code short.

import Qt 4.7
Rectangle {
    id: root
    width: 500; height: 500
    color: "red"
    Rectangle {
        id: square
        x: 150; y: 150; width: 200; height: 200
        color: "yellow"
        Rectangle {
            width: 50; height: 50; color: "black"
        }
        transform: Rotation {
            id: rotateSquare
            origin.x: 100; origin.y: 100; angle: 0
        }
        NumberAnimation {
            id: rotateAnim
            target: rotateSquare; property: "angle"
            from: 0; to: 360; duration: 1500
        }
        Connections {
            target: self
            onTheSignal: rotateAnim.start()
        }
    }
}
The code for the Connections element is highlighted in bold. Of its two attributes, the first, called 'target', specifies the object with signals that we want to bind handlers to. In this example the signal is a member of the global object and this complicates matters because it's not straightforward to write an expression which yields the global object. Hence, I placed the 'self' property on the global object to provide a convenient way of the getting a reference to it.

There are ways to get the global object, but they're not particularly pretty and I don't fully trust that kind of thing inside Qt's script environment anyway.

The second attribute specifies the signal binding. Specifically, the attribute name identifies the signal and is derived by pre-pending the string 'on' to the actual signal name. Hence, in this case, binding to 'theSignal' is specified using the attribute 'onTheSignal'. The value of the attribute is the JavaScript code to be executed when the signal fires. In our example it causes a simple little animation to occur.

Up to now, the only example I provided of using signals was the hsqml-morris demo application. It's not a great example of idiomatic QML because it uses a big chunk of JavaScript to work around some of the present limitations of HsQML's marshalling facilities (e.g. no lists/arrays). It makes no great attempt to be a "pure" QML application, so it just calls the signal's connect() method to attach it via JavaScript.

You could use the same approach with this test program by replacing the Connections element with the following code snippet:

        Component.onCompleted: {
            self.theSignal.connect(rotateAnim.start);
        }

The 'self' property is superfluous here because we can access the signal member on the global object directly. However, it's a slightly unfair comparison because the JavaScript code only covers connecting to the signal, whereas the Connections element also handles disconnections. When you're dynamically creating and destroying Components using things like the Repeater element, this is important to prevent overloading your signals with handlers that are never cleaned up.

The Connections element also allows the target attribute to be specified with a property or dynamic expression. If the value of the target expression changes at runtime then all the signal handlers will be disconnected and reconnected to the new object.

Addendum: Writing this example has made me think that HsQML relies too heavily on top-level data and instance declarations. I'd like to rectify that in the future by making QML classes first-class values on the Haskell side.
Categories: Offsite Blogs

Robin KAY: HsQML 0.3.0.0 released: Now with Qt 5

Planet Haskell - Fri, 07/04/2014 - 3:35pm
I've just made a new major release of HsQML, my Haskell binding for the Qt Quick GUI framework. You can download it from Hackage in the usual manner.

This is a particularly exciting release because it's the first to have been ported over to use Qt 5. Previously, HsQML was developed against an older version of the Qt Quick technology which shipped as part of Qt 4.7 and 4.8. Support for Qt 5 has been a constant theme in the e-mails I get concerning HsQML for some time and so I'm pleased to finally deliver on that point.

There are also number of other improvements to the library which should allow more idiomatic QML code and hence reduce the need for helper JavaScript. Properties now support an associated notify signal which allows QML to automatically update in response to property changes rather than needing manual signal handlers. Also, lists and Maybe values can be marshalled between Haskell and QML natively, again reducing friction between the two environments.

The API has been redesigned slightly so that object classes and signal keys can be defined directly inside Haskell functions in addition to the older type-class based method. It's unclear yet if this style is wholly superior but, for smaller programs at least, it permits greater clarity and much less verbosity.

Finally, although still far from comprehensive, I've spent some time trying to improve the documentation on my web-site. It now provides some more substantial examples and goes into greater depth. The complete buildable source code for these examples is contained in the hsqml-demo-samples package. Also, the original Nine Men's Morris demo application is still available, but the package has been renamed to hsqml-demo-morris.

release-0.3.0.0 - 2014.05.04

* Ported to Qt 5 and Qt Quick 2
* Added type-free mechanism for defining classes.
* Added type-free mechanism for defining signal keys.
* Added property signals.
* Added marshallers for Bool, Maybe, and lists.
* Added less polymorphic aliases for def functions.
* Replaced Tagged with Proxy in public API.
* Removed marshallers for URI and String.
* New design for marshalling type-classes (again).
* Generalised facility for user-defined Marshal instances.
* Relaxed Cabal dependency constraint on 'QuickCheck'.
* Fixed GHCi on Windows with pre-7.8 GHC.
Categories: Offsite Blogs

Robin KAY: HsQML 0.3.1.0 released

Planet Haskell - Fri, 07/04/2014 - 3:35pm
I've just released HsQML 0.3.1.0 which, as usual, is available for download from Hackage. This release fixes several stability issues and also introduces a facility for defining properties with the CONST attribute.

If you use a property defined on one of your Haskell objects in a QML expression and that property doesn't have an associated signal, then Qt will print the following warning:

Expression depends on non-NOTIFYable properties

For mutable objects, the accurately informs us that QML has no way of knowing if the value of that property changes. However, when using Haskell, we often prefer to work with immutable values and there was previously no way of informing Qt that the value would never change. Previously, the only course of action was to specify a dummy signal or to use nullary methods instead of properties. You can now use the new defPropertyConst function instead of defPropertyRO to specify that an associated signal is unnecessary and suppress this warning.

As an aside, Christopher Reichert has just written a blog post about using HsQML which is well worth the read.

release-0.3.1.0 - 2014.06.11

* Added properties with constant annotation.
* Added runtime warning for users of the non-threaded RTS.
* Added non-TH version of Setup.hs.
* Relaxed Cabal dependency constraint on 'transformers'.
* Fixed premature garbage collection of QML objects.
* Fixed intermittent crash on exit when firing signals.
* Fixed crash when using Cmd-Q to exit on MacOS.
Categories: Offsite Blogs

HART 2014 - deadline extended

General haskell list - Fri, 07/04/2014 - 3:11pm
We extended the deadline until 12th July. ========================================= CALL FOR PAPERS Second Workshop on Haskell And Rewriting Techniques (HART 2014) http://www.program-transformation.org/HART14/ To be held on September 5, co-located with ICFP 2014, the Haskell Symposium, etc., in Gothenburg. Haskell is an advanced purely-functional programming language. Pure functional programming is programming with equations, often defined by pattern-matching. Rewriting is the science of replacing equals by equals and thus a very powerful method for dealing with equations, often constructor-based. There are strong connections between Haskell (or generally, pure functional) programming and rewriting. The purpose of the HART workshop is to foster those connections. In addition to an invited talk by Oleg Kiselyov, we plan a half day of discussions, in an informal setting, on how Haskell (and related languages) and rewriting techniques and theories can cross-fert
Categories: Incoming News

How viable is using Haskell to make music? Should I be using Clojure + Overtone instead?

Haskell on Reddit - Fri, 07/04/2014 - 3:06pm

Hello!

I'm interested in learning a functional programming language, and I'm also interested in making music using code (i.e. 'live coding').

Haskell is the functional language I really want to learn, but it doesn't seem to have a lively and active music making community, unlike Clojure with Overtone + Supercollider. So far I've stumbled across Tidal, which while incredibly cool, isn't designed to fulfil all your music making needs, unlike Overtone.

So, what are you thoughts? Should I try and get over the abundance of brackets + the JVM, and go with Clojure?

Thanks,
Louis

edit: I found this, it looks cool. https://github.com/anton-k/csound-expression

submitted by MrPopinjay
[link] [24 comments]
Categories: Incoming News

Request for code review: Dynamic programming

Haskell on Reddit - Fri, 07/04/2014 - 2:46pm

A recent working-paper A Comparison of Programming Languages in Economics compares the performance of different languages for a dynamic optimization problem arising in economics. The original code is on GitHub.

The authors have not considered any functional programming languages, though they promise to do so in a later paper. I have independently reimplemented their program in Haskell

https://github.com/jmoy/avb-econ-hs

My program, which uses REPA runs about 3 times slower than the authors' C++ program. I would greatly appreciate comments on my code, particularly about ways it can be made faster without sacrificing the quality of expression too much. I do not want to end up writing C++ in Haskell.

submitted by yomritoyj
[link] [9 comments]
Categories: Incoming News

Type-level Nat to Integer

haskell-cafe - Thu, 07/03/2014 - 10:03pm
Hi all, I'm trying to change type-level Nat to Integer as following: {-# LANGUAGE DataKinds, KindSignatures, GADTs, PolyKinds #-} data Nat = Z | S Nat class NatToInt n where natToInt :: n -> Int instance NatToInt Z where natToInt _ = 0 instance NatToInt (S n) where natToInt = 1 + natToInt (undefined :: n) I understand why it fails (Z and S have not the right kind). How to specify that NatToInt is Nat-specific? Moreover, if you have any advanced explanations/links which could give me a deeper understanding on what going on, I'll take them. Thanks in advance for your help. _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe< at >haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Categories: Offsite Discussion

Final Call for Papers: OCL 2014 Submissions Due in OneWeek

General haskell list - Thu, 07/03/2014 - 4:15pm
(Apologies for duplicates) CALL FOR PAPERS 14th International Workshop on OCL and Textual Modeling Applications and Case Studies (OCL 2014) Co-located with ACM/IEEE 17th International Conference on Model Driven Engineering Languages and Systems (MODELS 2014) September 28-30 (tbc), 2014, VALENCIA, SPAIN http://www.software.imdea.org/OCL2014/ Modeling started out with UML and its precursors as a graphical notation. Such visual representations enable direct intuitive capturing of reality, but some of their features are difficult to formalize and lack the level of precision required to create complete and unambiguous specifications. Limitations of the graphical notations encouraged the development of text-based modeling languages that either integrate with or replace graphical notations for modeling. Typical examples of such languages are OCL, textual MOF, Epsilon, and Alloy. Textual modeling languages have thei
Categories: Incoming News

Haskell Weekly News: Issue 298

General haskell list - Thu, 07/03/2014 - 6:59am
Welcome to issue 298 of the HWN, an issue covering crowd-sourced bits of information about Haskell from around the web. This issue covers from June 15 to 28, 2014 Quotes of the Week * Kinnison * imagines a radio station playing only things like 'Life tru a Lens', stuff by 'Dire States' or 'Monadonna' Top Reddit Stories * Today I published an introductory book on Haskell Data Analysis Domain: haskelldata.com, Score: 99, Comments: 26 Original: [1] http://goo.gl/R2kRFu On Reddit: [2] http://goo.gl/Ka0oP5 * Backpack: An ML-like module system for Haskell Domain: plv.mpi-sws.org, Score: 76, Comments: 44 Original: [3] http://goo.gl/7Zkxbg On Reddit: [4] http://goo.gl/78H37f * Cgrep, a context-aware grep for source code. Domain: awgn.github.io, Score: 67, Comments: 13 Original: [5] http://goo.gl/q1VdEA On Reddit: [6] http://goo.gl/2NNTrO * Teenage Haskell Domain: twdkz.wordpress.com, Score: 63, Comments: 7 Original: [7] http://goo.gl/c
Categories: Incoming News

Closed type families, apartness, and occurs check

glasgow-user - Wed, 07/02/2014 - 9:19am
From the user manual, it sounds like a clause of a closed type family should be rejected once no subsitution of the type could make it unify with the clause. If so, it doesn't seem to do an occurs check: type family IsEq a b :: Bool where   IsEq a a = True   IsEq a b = False forall a . IsEq a a :: Bool = forall (a :: k). 'True forall a . IsEq a [a] :: Bool = forall a. IsEq a [a] I came across this while trying to using Generics to find the immediate children of a term - this sort of non-reduction happens while comparing a type like (Term var) with a constructor argument of type var. Brandon _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users< at >haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
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!

~d

Categories: Incoming News