FunBlocks - Blockly used for a functional language

650 views
Skip to first unread message

Stefan J

unread,
Jun 30, 2016, 11:01:17 AM6/30/16
to Blockly
Hi everyone

We are using Blockly in a educational project to generate code for a functional language. More specifically we are generating Haskell code in order to build CodeWorld applications

We are using a custom fork of Blockly, which is based on a version by Anthony for math expressions, which was based on a earlier version (another fork) of Blockly for types and polymorphism.
This version supports better typing of blocks and allows Blocks to be polymorphic.

Haskell is a strict, pure, functional language and we work on immutable data structures in CodeWorld. Each function in CodeWorld has a type and hence all of our Blocks have types. I think this makes it well suited for a block-based environment as we can expressively see how the program flows.

The majority of the application is currently in Haskell. The Haskell code is compiled to JavaScript through GHCJS. 
Once a user builds an application with the Blocks, and clicks run, code is generated for Haskell. This code is sent to the server, the code gets compiled again with GHCJS, using the CodeWorld libraries and the resulting program is then run in the browser.

We are generating Haskell CodeWorld code, instead of just running the application directly, as a means to teach programming to young students. Later they can use the full text UI for advanced programs.

We have a initial version of available at code.world/blocks, which is open sourced on Github.
This version currently supports:
  1. Building simple CodeWorld applications (pictures and transformations thereof)
  2. Generation of Haskell CodeWorld code and running it in the browser.
  3. Some use of polymorphic blocks (if, equality)
  4. Custom let definitions for variables (still a work in progress).
We might later on develop more advanced features that are used in functional languages, such as:
  • Recursion
  • Handling of first class typed functions
  • Algabraic data types
  • Pattern matching
I'm mainly posting this for this for those interested in some of the features we are working on, or to see if there is interest in such work. Maybe some of this could provide some utility for others doing something similar.

Neil Fraser

unread,
Jun 30, 2016, 9:02:15 PM6/30/16
to blo...@googlegroups.com
Very cool.  Interesting things happen when the system is stressed:



Maybe restrict percentages to reasonable values using field_number's constraints:
https://github.com/google/blockly/blob/master/core/field_number.js#L32

Also note that this is a simpler way of disabling unconnected blocks:
workspace.addChangeListener(Blockly.Events.disableOrphans);


--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Andrew N Marshall

unread,
Jul 1, 2016, 1:00:24 AM7/1/16
to Blockly
Fun stuff!


I had been chatting with the team here about functional languages.  It's great to see you work with something as strict as Haskell (even if it is a pretty simple application domain). Are there any areas you'd like to see improved to better support functional languages?

Stefan J

unread,
Jul 1, 2016, 2:42:06 AM7/1/16
to Blockly
@Neil, thanks for the tips !

@Andrew, I'll probably get a better idea of where the problem areas are as I get along to some more difficult features such as pattern matching or some parts of first class functions.

Currently the improved typing system and the polymorphic connectors, originally implemented in an old fork benefits us greatly. We also use different connectors to help differentiate between different types.

We are also using features of another fork and this causes our Blockly fork to be behind some 300 commits from the main one unfortunately.

Overall the Blockly project is great and saves us a load of time.

Zubair Quraishi

unread,
Jul 2, 2016, 1:20:31 AM7/2/16
to Blockly
Excellent work Stefan! I am building something called Blockly Builder which compiles to Clojure, so I am very excited to see that others such as yourself see this as interesting. Is this something you will be selling or is it just a hobby?


On Thursday, June 30, 2016 at 5:01:17 PM UTC+2, Stefan J wrote:

Stefan J

unread,
Jul 2, 2016, 3:04:34 AM7/2/16
to Blockly
I am doing it as part of this year's Summer of Haskell.

The project was originally based on a feature proposal for CodeWorld, which is a project by Chris Smith, used to teach younger students programming.
I don't think anything will be sold. The whole project is open source as well.

Zubair Quraishi

unread,
Jul 2, 2016, 9:02:19 AM7/2/16
to Blockly
Ok, well, it is definitely very cool. Blockly Builder is also open source and is here: https://github.com/zubairq/BlocklyBuilder
Reply all
Reply to author
Forward
0 new messages