Code Monkey home page Code Monkey logo

agda-frp-js's Introduction

An implementation of Functional Reactive Programming for building HTML applications in Agda.

To build and application, start with an HTML file:

  <html>
    <head>
      <title>Hello World</title>
      <script data-main="agda.frp.main" src="require.js"></script>
    </head>
    <body> 
      <h1>A greeting</h1>
      <p class="agda" data-agda="Demo.Hello"></p>
    </body>
  </html>

This is just a regular old HTML file, which loads the agda.frp.main JavaScript module (using require.js, but any AMD-compliant JavaScript module loader should work). The important part is:

  <p class="agda" data-agda="Demo.Hello"></p>

The "agda" class and data-agda attribute indicates that an Agda program should be executed inside the annotated node.

Now write an Agda program:

  open import FRP.JS.Behaviour using ( Beh ; [_] )
  open import FRP.JS.DOM using ( DOM ; text )
  open import FRP.JS.RSet using ( ⟦_⟧ )

  module Demo.Hello where
 
  main :  {w}  ⟦ Beh (DOM w) ⟧
  main = text ["Hello, world."]

This program creates a text node whose content is always "Hello, World."

Compile (using the darcs snapshot of Agda 2.2.11):

  agda --js Demo/Hello.agda

this will create a bunch of js files such as jAgda.Demo.Hello.js.

Put all the .js files (including require.js and the agda.frp.*.js files) in the same directory as hello.html.

Load hello.html in a browser, and enjoy.

There are unit tests in FRP.JS.Test, which link against John Resig's QUnit (http://docs.jquery.com/QUnit). To run the tests, first "make tests", then load build/tests.html in a browser.

agda-frp-js's People

Contributors

andreasabel avatar larrytheliquid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agda-frp-js's Issues

Duplicate binding for built-in thing LEVEL (2.4.2)

Running make all:

[shana@lenalee:/tmp]$ nix-build ~/programming/nixpkgs/ -A agdaFrpJs -o /tmp/agda-frp-js
these derivations will be built:
  /nix/store/p8ym2x8bals2wa3bj8iswzvz3kdf6kf8-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv
building path(s) `/nix/store/d18kgl7g1przdisk2bxszy9cnsw1sw8w-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c'
building /nix/store/d18kgl7g1przdisk2bxszy9cnsw1sw8w-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c
unpacking sources
unpacking source archive /nix/store/h24nayllk3wgjdiv3iajf72q29x578vz-git-export
source root is git-export
patching sources
configuring
building
building dist/
 mkdir dist
building dist/require.js
 cp src/js/require.js dist/require.js
building dist/agda.frp.js
 cp src/js/agda.frp.js dist/agda.frp.js
building dist/agda.frp.main.js
 cp src/js/agda.frp.main.js dist/agda.frp.main.js
building dist/agda.frp.signal.js
 cp src/js/agda.frp.signal.js dist/agda.frp.signal.js
building dist/agda.frp.time.js
 cp src/js/agda.frp.time.js dist/agda.frp.time.js
building dist/agda.frp.taskqueue.js
 cp src/js/agda.frp.taskqueue.js dist/agda.frp.taskqueue.js
building dist/agda.mixin.js
 cp src/js/agda.mixin.js dist/agda.mixin.js
building dist/agda.box.js
 cp src/js/agda.box.js dist/agda.box.js
building dist/agda.array.js
 cp src/js/agda.array.js dist/agda.array.js
building dist/agda.keys.js
 cp src/js/agda.keys.js dist/agda.keys.js
building dist/agda.object.js
 cp src/js/agda.object.js dist/agda.object.js
building dist/jAgda.FRP.JS.Demo.Hello.js
 agda -i src/agda -i demo/agda --js --compile-dir dist demo/agda/FRP/JS/Demo/Hello.agda
Checking FRP.JS.Demo.Hello (/tmp/nix-build-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv-0/git-export/demo/agda/FRP/JS/Demo/Hello.agda).
 Checking FRP.JS.Behaviour (/tmp/nix-build-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv-0/git-export/src/agda/FRP/JS/Behaviour.agda).
  Checking FRP.JS.Bool (/tmp/nix-build-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv-0/git-export/src/agda/FRP/JS/Bool.agda).
   Checking FRP.JS.Primitive (/tmp/nix-build-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv-0/git-export/src/agda/FRP/JS/Primitive.agda).
    Checking FRP.JS.Level (/tmp/nix-build-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv-0/git-export/src/agda/FRP/JS/Level.agda).
/tmp/nix-build-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv-0/git-export/src/agda/FRP/JS/Level.agda:15,1-32
Duplicate binding for built-in thing LEVEL, previous binding to
.Agda.Primitive.Level
when checking the pragma BUILTIN LEVEL Level
make: *** [dist/jAgda.FRP.JS.Demo.Hello.js] Error 1
builder for `/nix/store/p8ym2x8bals2wa3bj8iswzvz3kdf6kf8-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv' failed with exit code 2
error: build of `/nix/store/p8ym2x8bals2wa3bj8iswzvz3kdf6kf8-agda-frp-js-aadb8dd38551e0ecad8e4e3cd2f8264fe58fa35c.drv' failed

non-behavior DOM

@asajeffrey
I might be missing something obvious, but it seems like one either needs to be able to construct the dom outside of behaviors (rather than postulating Beh DOM's directly), or have a "join" operator:

This gist contrasts building a string behavior from a list with trying to accomplish the same thing by rendering the list as a dom of li-tags. You get into trouble because what you are folding over is already a dom, so mapping it will wrap it again. Solutions could be the ability to create non-behavior dom values, or a "join" operator to flatten the wrapping.
Would either one of these be ok, or is there something vital you are trying to protect by not allowing non-behavior dom values (e.g. maybe there is a conflict with the way you are connecting to dom events)?
https://gist.github.com/2b949aeecdb936220810

Calculator demo fails to compile

I don't know if you've actively looked at this project in a while, but at the moment the calculator demo fails to compile.

~/agda-frp-js/demo/agda/FRP/JS/Demo/Calculator/View.agda:28,21-47
Cannot instantiate the metavariable _130 to solution .w since it
contains the variable .w which is not in scope of the metavariable
or irrelevant in the metavariable but relevant in the solution
when checking that the expression display (model evt) ++ dom has
type Beh (DOM .w) .t
make: *** [dist/jAgda.FRP.JS.Demo.Calculator.js] Error 1

I'm running make all using an installation of Agda 2.3.2.2 (on OSX 10.6.8, but I don't think that would matter).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.