Stdlib

From Predictive Chemistry
Revision as of 09:55, 26 September 2014 by David M. Rogers (talk | contribs) (Created page with "<source lang="haskell"> /* Stdenv v 0.4 * * To be run once, create some useful standard objects, and save * as a commit structure (for later loading into stdenv-s). * * …")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

<source lang="haskell"> /* Stdenv v 0.4

*
*  To be run once, create some useful standard objects, and save
* as a commit structure (for later loading into stdenv-s). 
*
*   Create some useful primitives from the base commands,
* 'typeof', 'commit', 'load_prim', and 'load_base'
*/

-- Test types Nat : ⋆ Z : Nat Succ : Nat → Nat

-- Simple functions id = λ x → x seq = λ a b → b const = λ a b → a flip = λ f a b → f b a

>>= = applyIO =<< = flip (>>=) infixl >>= 1 infixr =<< 1

-- $ : <a,b : 'kind> -> (a -> b) -> a -> b $ : (a -> b) -> a -> b $ = fun f x -> f x infixr $ 0

IO : (a : 'kind) -> 'kind ST : (a : 'kind) (r : 'kind) -> 'kind

rm := Prim =<< commit {

        name = "rm",
        ptype = type String -> IO(Nil),
        n=1, extn = 1, -- IO prim
        API = "",
        reduce = "
  1. include <ast.h>
  2. include <cli.h>

Ast *reduce(prim_cb_t *cb, struct Prim *p) {

   struct Environ *e = (struct Environ *)cb->st;
   if(p->t[0]->type != TBase || p->t[0]->base->type != TString) {
       printf(\"rm() called on non-string\\n\");
       return mkNil();
   }
   p9remove(e, p->t[0]->base->name);
   return mkNil();

}", }

/* More work to do: unitIO applyIO unitST applyST

rm pwd ls cd open gc_stat

  • /

-- Save current project as a commit. -- commit_proj "stdenv-0.2"

-- string cat ++ = Prim "b1c9a203f71d2e5bdc4ee2378de3ab2fdb1d8352" -- string slice !% = Prim "992740f62d4ca2f2ca9f6f6cf9274d8b9626a7c2" strlen = Prim "2081afb248e480a8f6ca6220156c69d7ac938ef8" infixl ++ 4 infix !% 5

</source>