Tips for starting develop in F# in Atom

After some days working with Atom to write in F# code, here are some tips:

.) Read the manual and use the ionide-installer package 😉

On my first try I installed some ionide packages and so some features where missing. So really read the manual and use the ionide-installer package.

.) On Mac OS X – use the Mono package and not the one from Homebrew

When you are using the Homebrew version, Ionide can not spawn the background service for the autocompletion.
If you use the Mono one from http://www.mono-project.com/download/ everything works.
Additional this package includes the reference assemblies for Portable Class Libraries. Without them you can not compile a PCL.

.) Additional packages

.) using Yeoman and the generator-fsharp

Yeoman with the F#- Generator (https://github.com/fsprojects/generator-fsharp) is a nice tool for creating new projects from templates.
I added some new features in the last view days:

Hopefully they will be merged in the next days.

On the bleeding edge – Akka.Net + Suave.io + DNX in F#

So after playing with Suave.io, I wanted to add some new bleeding edge stuff to it. 😉 And run it on a beta environment, the DNX 🙂

First, the complete source of it is here: https://github.com/SabotageAndi/SuaveAkkaCore

Thanks to Alxandr there is F# support for the DNX: https://github.com/YoloDev/YoloDev.Dnx.FSharp

So here is a quick go through of the code to get the stuff working:

1.) Add needed NuGet feeds

YoloDev: https://www.myget.org/F/yolodev/api/v2″
AspNetVNext: https://www.myget.org/F/aspnetvnext/api/v2″

2.) Adapt project.json for F# Support:

{
“version”: “1.0.0-beta-*”,
“dependencies”: {
“YoloDev.Dnx.FSharp”: { “type”: “build”, “version”: “1.0.0-beta-*” },
   “Suave”: “0.29.1”,
        “Akka”: “1.0.3”,
        “Akka.FSharp”: “1.0.3”
},
“frameworks”: {
“dnx451”: {
“frameworkAssemblies”: {
“System.Runtime”: “”,
“System.Threading.Tasks”: “”
}
}
},
“compiler”: {
“name”: “F#”,
    “compilerAssembly”: “YoloDev.Dnx.FSharp”,
    “compilerType”: “YoloDev.Dnx.FSharp.FSharpProjectCompiler”
}
}

The bold text are the changes needed for the F# support, the italic one are the needed changes for Akka.net and Suave.io.

 

3.) initialize Akka.net & Suave.io

 member x.Main () =
    use akkaSystem = System.create "SuaveAkkaCore" (Configuration.defaultConfig()) //1
  
    spawn akkaSystem "root" (actorOf2 handleRequest) |> ignore //2
  
    let cts = new CancellationTokenSource()
    
    let startingServer, shutdownServer = startWebServerAsync defaultConfig (app akkaSystem) //3
    Async.Start(shutdownServer, cts.Token)
    
    startingServer |> Async.RunSynchronously |> printfn "started: %A"

    printfn "Press Enter to stop"
    Console.Read() |> ignore

    
    cts.Cancel()

on //1 the Akka System is created with a standard configuration. It is named “SuaveAkkaCore”. This is later important to find the actor again.
The only one actor (named root) in this example is spawnd on //2. When the actor gets a message, the handleRequest function is called.
Last part on initializing the system is on //3 the start of suave. Here is only one webpart involved.

4.) Suave webpart

 let app system : WebPart = 
      fun (httpContext : HttpContext) ->
          async {
              let response = sendRequestToActor system httpContext
              return! response
          }

It’s a simple web part that reacts on every request and calls the sendRequestToActor method with the current Akka system and HttpContext (there is the request, response stuff in Suave).

5.) sending message to actor

let sendRequestToActor system (httpContext : HttpContext) =
    
    let callActor = async { 
      let actor = select "akka://SuaveAkkaCore/user/root" system
      let! resp = actor <? httpContext
      return Some resp
    }
   
    let response = callActor |> Async.RunSynchronously
    response httpContext   

In the first part, the root- Actor is selected. Here is the system name and actor name needed.
With the <? operator, the actor is asked with the HttpContext.
After that, we run the async workflow and return the response.

6.) the actor function itself

 let handleRequest (mailbox : Actor<'a>) (msg : HttpContext) =
    let url = msg.request.url.ToString()                                     
    mailbox.Sender() <! (OK url)

In the actor function, we get the mailbox and the message as parameters. Here I simply take the request url and return it as OK response.

To run the stuff, you need the DNX runtime installed.
Switch to the mono runtime for dnx with “dnvm use 1.0.0-beta6-12120 -p -r mono”
With a “dnu restore” you get the needed packages.
After that, a “dnx . run” starts the program.

Now browse to http://localhost:8083 and you see as response the browsed url.

Have fun!

I am on GitHub

I finally found some time to push some of my projects to GitHub.

.) Efl- Sharp – https://github.com/SabotageAndi/efl-sharp
My C# bindings for the Enlightenment Foundation Libraries. I didn’t have much time in the last weeks to work further on them, but I will need them for another project, so there will be more new stuff in the future.

.) uTouch Gentoo ebuilds – https://github.com/SabotageAndi/gentoo-portage-overlay
I ported my intial ebuilds to the latest versions of various packages and took the opportunity to also push these to GitHub.
In the repository will be also other ebuilds, as an ebuild for the driver for the Ralink rt3572 wlan chip.

 

Have fun with it.

Resurrect this blog & my current personal project

It is long ago that I wrote the last blog post here, but in the future I hope there will be more posts with lots of interessting development stuff 😉

And here is the interessting stuff.

I started writing C# bindings for the Enlightenment Foundation Libraries (EFL). They are used in the windowmanager E17 and are designed for usage from small, embedded devices up to multi core desktop pc’s.

You will find all important information on their website: www.enlighenment.org

You can find the sources here: http://dl.dropbox.com/u/21420050/efl-sharp.tar.gz

I started implementing some common elementary widgets and some methods of edje to load an edje-file and get the loaded widgets.

What does currently not  work:
.) EinaList
There is some code for that already there, but it does not work at all.

.) The autotools build system
I used MonoDevelop as my IDE, which should generate Makefiles and all the stuff. But there are some major bugs in this generation. I didn’t have the time until now to fill bugs or patch MonoDevelop, but this is on top of my todo list.

How to get something build that is working
1.) run autogen.sh
2.) build the bindings with MonoDevelop
3.) run sudo make install
4.) go to %PREFIX%/lib/efl-sharp – here are the assemblies installed
5.) add executable right to all dll’s with sudo chmod +x *.dll
6.) install the libraries in the Global Assembly Cache: run for every dll-file sudo gacutil -i %FILENAME% -package efl-sharp

Now you have installed the libraries and you can work with it.

As an example app I started to write the RSS- reader efeed.
You can get the sources from here: http://dl.dropbox.com/u/21420050/efeed.tar.gz
A screenshot: http://dl.dropbox.com/u/21420050/efeed.png

Currently it is more an example and test app, but I plan to extend it to a more usefull application.

I appreciate any feedback and suggestions for efl-sharp and efeed

Mono 1.9.1 for Openmoko Freerunner

After long work and switching to another machine I was able to build mono 1.9.1 for the freerunner.

To install it, download the file and rename it to openmoko_mono_1.9.1.tar.gz. This archive contains all necessary dependecies to install mono, but I removed the debug versions to save space.

I am using the stable repository on my freerunner, but build mono with the org.openmoko.dev branch because there was already the openembedded bitbake recipts. So before you can install mono you have to update libglib and libgthread.

Next install mono. Opkg will install several dependecies from the 1.2.5.1 version and download them from Openmoko. Let him do and after opkg is finished, execute opkg list_installed | grep mono. Then simply update every single package to version 1.9.1 until all installed mono packages are from version 1.9.1. At the end, you have to update libnunit.

After all you should get this on the terminal on your phone:

I added also an updated sqlite version to the package, because with the installed version, mono has a problem to find an entry point in the native lib.

Download for unstable/testing Branch Users:

(see Post: http://sabotageandi.wordpress.com/2008/10/21/updating-stable-libs-with-dev-is-not-a-good-idea)

Mono 1.9.1 for Openmoko Freerunner

My next steps are to get gtk-sharp and NDesk.DBus to work and to get my changes for the bitbake recipts into the Openmoko/OpenEmbedded branch.

Have fun and stay tuned