From f0c44b94775a741017e7fefb9246e40d5047a280 Mon Sep 17 00:00:00 2001 From: depsterr Date: Sun, 23 Jan 2022 12:52:33 +0100 Subject: [PATCH] added some build stuff --- .gitignore | 3 +++ LICENSE | 7 +++++++ app/Main.hs | 2 ++ hm.cabal | 31 +++++++++++++++++++++++++++++++ hm.cf | 26 +++++++++++++++++--------- readme.md | 16 ++++++++++++++++ 6 files changed, 76 insertions(+), 9 deletions(-) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 app/Main.hs create mode 100644 hm.cabal create mode 100644 readme.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d3883d6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +Makefile +Hm +dist-newstyle diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..9ae36a7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,7 @@ +ISC License + +Copyright 2022 depsterr + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/app/Main.hs b/app/Main.hs new file mode 100644 index 0000000..d582e1e --- /dev/null +++ b/app/Main.hs @@ -0,0 +1,2 @@ +main :: IO () +main = pure () diff --git a/hm.cabal b/hm.cabal new file mode 100644 index 0000000..5d85bf2 --- /dev/null +++ b/hm.cabal @@ -0,0 +1,31 @@ +cabal-version: 2.4 +name: hm +version: 0.1.0.0 +synopsis: toy programming language +-- description: +homepage: https://githug.xyz/depsterr/hm +-- bug-reports: +license: ISC +license-file: LICENSE +author: depsterr +maintainer: depsterr@protonmail.com +-- copyright: +category: Programming Language + +library + ghc-options: -Werror=incomplete-patterns -Wall -fno-warn-name-shadowing + , Simple.CC + build-tool-depends: alex:alex >= 3.0, happy:happy >= 1.19.5 + build-depends: base >=4 + , array + , containers + , transformers + , mtl + hs-source-dirs: src + default-language: Haskell2010 + +executable sexprml + main-is: Main.hs + build-depends: base >=4, hm + hs-source-dirs: app + default-language: Haskell2010 diff --git a/hm.cf b/hm.cf index 02a181b..2bc8a04 100644 --- a/hm.cf +++ b/hm.cf @@ -1,4 +1,6 @@ layout toplevel ; +layout "let" ; +layout stop "in" ; entrypoints [Def], Exp ; @@ -7,12 +9,14 @@ token Id ((letter|digit|["[]_"])+) ; comment "--" ; comment "{-" "-}" ; -TypeDef. Def ::= "type" TypeSig1 "|" [Decl] ; +TypeDef. Def ::= "type" TypeSig1 [Decl] ; VarDef. Def ::= Id ":" TypeSig ":=" Exp ; separator Def ";" ; -Decl. Decl ::= Id ":" TypeSig ; -separator nonempty Decl "|" ; +Decl. Decl ::= Id ":" TypeSig ; +[]. [Decl] ::= ; +(:). [Decl] ::= "|" Decl [Decl]; +-- todo custom [Decl] TypeFun. TypeSig ::= TypeSig1 "→" TypeSig ; TypeApp. TypeSig1 ::= Id [TypeSig2] ; @@ -21,12 +25,16 @@ coercions TypeSig 2; separator nonempty TypeSig2 "" ; -ExpTyped. Exp ::= Exp1 ":" TypeSig ; -ExpAbs. Exp1 ::= "λ" [Id] "." Exp2 ; -ExpApp. Exp2 ::= Exp3 [Exp3] ; -ExpVar. Exp3 ::= Id ; +ExpLet. Exp ::= "let" "{" [Assign] "}" "in" Exp2 ; +ExpTyped. Exp1 ::= Exp2 ":" TypeSig ; +ExpAbs. Exp2 ::= "λ" [Id] "." Exp3 ; +ExpApp. Exp3 ::= Exp4 [Exp4] ; +ExpVar. Exp4 ::= Id ; -separator nonempty Exp3 "" ; -coercions Exp 3; +Assign. Assign ::= Ident "=" Exp1 ; +separator nonempty Assign ";" ; + +separator nonempty Exp4 "" ; +coercions Exp 4 ; separator nonempty Id "" ; diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..f0944bc --- /dev/null +++ b/readme.md @@ -0,0 +1,16 @@ +# HM + +A simple, terminating, pure, hindley milner lambda calculus with inductively defined types. + +## Building + +Depends: + * BNFC + * GNU make + * GHC + * Cabal + +Instructions: + * Run `bnfc -dm --text-token --functor hm.cf` + * Run `make` + * Run `cabal build`