hamler-lang / hamler Goto Github PK
View Code? Open in Web Editor NEWHaskell-style functional programming language running on Erlang VM.
Home Page: https://www.hamler-lang.org/
License: BSD 3-Clause "New" or "Revised" License
Haskell-style functional programming language running on Erlang VM.
Home Page: https://www.hamler-lang.org/
License: BSD 3-Clause "New" or "Revised" License
-- declare a Person record
data Person = Person {name :: String, age :: Integer}
p = Person {name = "John", age = 12}
-- update a Person record
p1 = p {name = "Miles", age = 20}
-- getters
name = p1.name :: String
age = p1.age :: Integer
e:
> let t = 1
> let (a,b) = (1,2)
A list comprehension consists of four types of elements: generators, guards, local bindings, and targets:
squares = [x * x | x <- [1..10]]
-- multiple generators
[(x,y) | x <- [1,2,3], y <- [4,5]]
-- dependent generators
[(x,y) | x <- [1..3], y <- [x..3]]
-- guards
[x | x <- [1..10], even x]
The error message:
$ hamler repl hamler: /Users/jxxcarlson/dev/elm/projects/src: getDirectoryContents:openDirStream: does not exist (No such file or directory)
example:
test :: IO ()
test = do
x <- getLine
return ()
-- New map
m = #{"foo" => "bar", "bar" => "foo"}
-- Match Map
#{"foo" := a, "bar" := b} = m
-- get, put
Map.get "foo" m -- a = "bar"
Map.get "bar" m -- b = "foo"
m1 = Map.put "key" "val"
-- keys, values
let keys = Map.keys m
let values = Map.values m
Add more FFI functions:
Hi! I am currently trying out Hamler and produced the following code:
module Main where
import Prelude
import Data.Maybe
import Data.String as String
main :: IO ()
main = print "Let there be Hamler, running on Erlang VM!"
checkPasswordLength :: String -> Maybe String
checkPasswordLength password =
case (String.length password > 20) of
true -> Nothing
false -> Just password
cleanWhitespace :: String -> Maybe String
cleanWhitespace string =
case (isSpace x) of
true -> cleanWhitespace xs
false -> Just $ x <> xs
where
(x, xs) = (String.take 1 string, String.drop 1 string)
isSpace :: String -> Bool
isSpace " " = true
isSpace "\t" = true
isSpace "\n" = true
isSpace _ = false
(Purely for educational purposes).
I tried to run the following code in the REPL, but then got this error:
checkPasswordLength "test" >>= cleanWhitespace
Error: error, Reason: undef
Stacktrace:[{'Main',checkPasswordLength,["test"],[]},
{'$PSCI',it,0,[]},
{replsrv__escript__1591__956394__873330__5,reploop,1,
[{file,"/usr/local/lib/hamler/bin/replsrv"},{line,31}]},
{escript,run,2,[{file,"escript.erl"},{line,758}]},
{escript,start,1,[{file,"escript.erl"},{line,277}]},
{init,start_em,1,[]},
{init,do_boot,3,[]}]
Copy the lib, ebin file to the specified location during make install.
> data Person = Person {name :: String, age :: Integer}
> p = Person {name = "John", age = 12}
Error found:
in module $PSCI
at :1:5 - 1:37 (line 1, column 5 - line 1, column 37)
Could not match type
Record
with type
Function
{ age :: Integer
, name :: List Char
}
while trying to match type { age :: t1
, name :: t0
| t2
}
with type { age :: Integer
, name :: List Char
}
-> Person
while checking that expression $0
has type { age :: t1
, name :: t0
| t2
}
in value declaration p
where t2 is an unknown type
t0 is an unknown type
t1 is an unknown type
{- Tuple -}
(1, "a", true)
(1, "a")
-- fst, snd
fst (1, "a") -- 1
snd (1, "a") -- "a"
{- List --}
[] -- empty list
[1,2,3] -- Integer list
[x|xs] -- Cons operator
[1|[2,3]] -- Cons
[1|[2|[3|[]]]] -- Cons
[x|_] -- List pattern
[_|xs] -- List pattern
{- Enumerations, Range -}
[1..10]
[1, 3..100]
['a'..'z']
Hi @emqplus! I am currently on 2ed8e60
I ran make
in the repository, as per the instructions, and got this error message:
[4 of 6] Compiling Paths_hamler
Linking .stack-work/dist/x86_64-linux-tinfo6/Cabal-2.4.0.1/build/hamler/hamler ...
hamler > copy/register
Installing library in /home/hecate/Contrib/hamler/.stack-work/install/x86_64-linux-tinfo6/26be186915af48c23b4d2cb254a5f277633539a42b7d0b2dcd2341150524febf/8.6.5/lib/x86_64-linux-ghc-8.6.5/hamler-0.1-KXX99Vk5BRn7EMIEvQosIn
Installing executable hamler in /home/hecate/Contrib/hamler/.stack-work/install/x86_64-linux-tinfo6/26be186915af48c23b4d2cb254a5f277633539a42b7d0b2dcd2341150524febf/8.6.5/bin
Registering library for hamler-0.1..
Completed 171 action(s).
lib/Control/OTP/Supervisor/Behaviour.erl:22: Warning: variable 'Class' is unused
Compiling Data.Void
Compiling Data.Tuple
hamler: FunDef (Constr (FunName (Atom "elem",2))) (Ann (Lam [Var (Constr "_0"),Var (Constr "_1")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "element"))))) [Expr (Constr (EVar (Var (Constr "_0")))),Expr (Constr (EVar (Var (Constr "_1"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "elem")),CLit (LInt 2)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Data.Show
Compiling Data.Semiring
hamler: FunDef (Constr (FunName (Atom "addInt",2))) (Ann (Lam [Var (Constr "_0"),Var (Constr "_1")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "+"))))) [Expr (Constr (EVar (Var (Constr "_0")))),Expr (Constr (EVar (Var (Constr "_1"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "addInt")),CLit (LInt 2)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
hamler: FunDef (Constr (FunName (Atom "showIntImpl",1))) (Ann (Lam [Var (Constr "_0")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "integer_to_list"))))) [Expr (Constr (EVar (Var (Constr "_0"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "showIntImpl")),CLit (LInt 1)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Data.Ref
hamler: FunDef (Constr (FunName (Atom "makeRef",0))) (Ann (Lam [] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "make_ref"))))) [])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "makeRef")),CLit (LInt 0)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Data.Record
Compiling Data.Port
Compiling Data.Int
Compiling Data.Functor
Compiling Data.Function
hamler: FunDef (Constr (FunName (Atom "error",1))) (Ann (Lam [Var (Constr "_0")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "error"))))) [Expr (Constr (EVar (Var (Constr "_0"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "error")),CLit (LInt 1)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
hamler: FunDef (Constr (FunName (Atom "mapListImpl",2))) (Ann (Lam [Var (Constr "_0"),Var (Constr "_1")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "lists")))),Expr (Constr (Lit (LAtom (Atom "map"))))) [Expr (Constr (EVar (Var (Constr "_0")))),Expr (Constr (EVar (Var (Constr "_1"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "mapListImpl")),CLit (LInt 2)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Data.Enum
hamler: FunDef (Constr (FunName (Atom "enumCharRange",2))) (Ann (Lam [Var (Constr "_0"),Var (Constr "_1")] (Expr (Constr (Case (Exprs (Constr [Constr (EVar (Var (Constr "_0"))),Constr (EVar (Var (Constr "_1")))])) [Constr (Alt (Pats (Constr [Constr (PVar (Var (Constr "Start"))),Constr (PVar (Var (Constr "Stop")))])) (Guard (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom ">="))))) [Expr (Constr (EVar (Var (Constr "Stop")))),Expr (Constr (EVar (Var (Constr "Start"))))])))) (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "lists")))),Expr (Constr (Lit (LAtom (Atom "seq"))))) [Expr (Constr (EVar (Var (Constr "Start")))),Expr (Constr (EVar (Var (Constr "Stop")))),Expr (Constr (Lit (LInt 1)))])))),Constr (Alt (Pats (Constr [Constr (PVar (Var (Constr "Start"))),Constr (PVar (Var (Constr "Stop")))])) (Guard (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "<"))))) [Expr (Constr (EVar (Var (Constr "Stop")))),Expr (Constr (EVar (Var (Constr "Start"))))])))) (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "lists")))),Expr (Constr (Lit (LAtom (Atom "seq"))))) [Expr (Constr (EVar (Var (Constr "Start")))),Expr (Constr (EVar (Var (Constr "Stop")))),Expr (Constr (Lit (LInt (-1))))])))),Ann (Alt (Pats (Constr [Constr (PVar (Var (Constr "_4"))),Constr (PVar (Var (Constr "_3")))])) (Guard (Expr (Constr (Lit (LAtom (Atom "true")))))) (Expr (Constr (PrimOp (Atom "match_fail") [Expr (Constr (Tuple [Expr (Constr (Lit (LAtom (Atom "function_clause")))),Expr (Constr (EVar (Var (Constr "_4")))),Expr (Constr (EVar (Var (Constr "_3"))))]))])))) [CLit (LAtom (Atom "compiler_generated"))]])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "enumCharRange")),CLit (LInt 2)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Data.Char
Compiling Data.Bool
Compiling Data.Bits
hamler: FunDef (Constr (FunName (Atom "band",2))) (Ann (Lam [Var (Constr "_0"),Var (Constr "_1")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "band"))))) [Expr (Constr (EVar (Var (Constr "_0")))),Expr (Constr (EVar (Var (Constr "_1"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "band")),CLit (LInt 2)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Data.Atom
hamler: FunDef (Constr (FunName (Atom "atom",1))) (Ann (Lam [Var (Constr "_0")] (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "list_to_atom"))))) [Expr (Constr (EVar (Var (Constr "_0"))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "atom")),CLit (LInt 1)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
hamler: FunDef (Constr (FunName (Atom "isControl",1))) (Ann (Lam [Var (Constr "_0")] (Expr (Constr (Case (Expr (Constr (EVar (Var (Constr "_0"))))) [Constr (Alt (Pats (Constr [Constr (PLit (LInt 127))])) (Guard (Expr (Constr (Lit (LAtom (Atom "true")))))) (Expr (Constr (Lit (LAtom (Atom "true")))))),Constr (Alt (Pats (Constr [Constr (PVar (Var (Constr "C")))])) (Guard (Expr (Constr (Let ([Var (Constr "_1")],Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "=<"))))) [Expr (Constr (Lit (LInt 0))),Expr (Constr (EVar (Var (Constr "_0"))))]))) (Expr (Constr (Let ([Var (Constr "_2")],Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "=<"))))) [Expr (Constr (EVar (Var (Constr "_0")))),Expr (Constr (Lit (LInt 31)))]))) (Expr (Constr (ModCall (Expr (Constr (Lit (LAtom (Atom "erlang")))),Expr (Constr (Lit (LAtom (Atom "and"))))) [Expr (Constr (EVar (Var (Constr "_1")))),Expr (Constr (EVar (Var (Constr "_2"))))])))))))))) (Expr (Constr (Lit (LAtom (Atom "true")))))),Constr (Alt (Pats (Constr [Constr (PVar (Var (Constr "_4")))])) (Guard (Expr (Constr (Lit (LAtom (Atom "true")))))) (Expr (Constr (Lit (LAtom (Atom "false"))))))])))) [CTuple [CLit (LAtom (Atom "function")),CTuple [CLit (LAtom (Atom "isControl")),CLit (LInt 1)]]])
CallStack (from HasCallStack):
error, called at src/Language/Hamler/Make/Actions.hs:135:25 in hamler-0.1-KXX99Vk5BRn7EMIEvQosIn:Language.Hamler.Make.Actions
Compiling Control.OTP.GenStatem.Types
Compiling Control.OTP.GenServer.Types
Compiling Control.OTP.GenEvent.Types
Compiling Control.OTP.Application.Behaviour
hamler: thread blocked indefinitely in an MVar operation
make: *** [Makefile:9: build] Error 1
When trying to split a string at some index in the REPL, I get this error:
> import Data.String as String
> string = "abcde"
> (x, xs) = (String.take 1 string, String.drop 1 string)
Unexpected token '=' at line 1, column 9
👋🏻
Where I can find the hamler formula on homebrew-core or cask repo's?
$ brew search hamler
No formula or cask found for "hamler".
The formula from the repository below is valid?
https://github.com/hamler-lang/homebrew-hamler
e:
p = { name = "A" , age = 30 }
p1 = p {name ="B"}
-- { name="B",age = 30}
I love Erlang and agree with most of the motivations for the BEAM VM in the docs intro. The idea of strongly typed ML-style language on BEAM will most certainly build traction. However the Mac-only instructions, for both installation and source build, are a deterrent. Is there a Linux option?
PSCi, version 0.13.6
Type :? for help
> a = 2
> a
hamler: fd:4: hPutChar: resource vanished (Broken pipe)
If this helps, I am on Mac mojave 10.14.4
and I installed hamler via brew.
$ uname -a
Darwin tejas 18.5.0 Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64 x86_64
Implement an experimental interpreter for the hamler language.
Is ARM platform currently supported?
In the README, is is mentioned to use brew
to install Erlang. However this can lead to a mess and this is specific to macOS.
kerl
is community accepted Erlang version management all-in-one tool, better to suggest using it:
{- Enumerations, Range -}
[1..10]
[1, 3..100]
['a'..'z']
error report:
hamler: /var/folders/mw/z9jgr5q93wqcxf7zws_5vw4w0000gn/T//hamlerTmp: createDirectory: already exists (File exists)
Hi, The hamler.cabal
file is automatically generated by hpack
. If you want to commit a new version of the package.yaml
file, I think you should also commit the new version of the hamler.cabal
file or remove the hamler.cabal
file from the repository.
/path/to/hamler/hamler.cabal was modified manually. Ignoring /path/to/hamler/package.yaml in favor of the cabal file.
If you want to use the package.yaml file instead of the cabal file,
then please delete the cabal file.
verbus@ubuntu-s-4vcpu-8gb-nyc3-01:~/hamler$ make
STACK_YAML="stack.yaml" stack run build -- -l
Getting project config file from STACK_YAML environment
/home/verbus/hamler/hamler.cabal was modified manually. Ignoring /home/verbus/hamler/package.yaml in favor of the cabal file.
If you want to use the package.yaml file instead of the cabal file,
then please delete the cabal file.
DEPRECATED: The package at Archive from https://github.com/hamler-lang/purescript/archive/af96a35346a0f1004eba4598d64fee271621f29e.tar.gz does not include a cabal file.
Instead, it includes an hpack package.yaml file for generating a cabal file.
This usage is deprecated; please see commercialhaskell/stack#5210.
Support for this workflow will be removed in the future.
lib/Control/OTP/Supervisor/Behaviour.erl:22: Warning: variable 'Class' is unused
Compiling Data.Void
Compiling Data.Tuple
Compiling Data.Show
Compiling Data.Unit
Compiling Data.Semiring
Compiling Data.Semigroup
Compiling Data.Ring
Compiling Data.Ref
Compiling Data.Record
Compiling Data.Port
Compiling Data.Pid
Compiling Data.Int
Compiling Data.Functor
Compiling Data.Function
Compiling Data.Eq
Compiling Data.Ordering
Compiling Data.Monoid
Compiling Data.Foldable
Compiling Data.Ord
Compiling Data.Enum
Compiling Data.Char
Compiling Data.Bool
Compiling Data.Bits
Compiling Data.Atom
Compiling Control.OTP.GenStatem.Types
Compiling Control.OTP.GenServer.Types
Compiling Control.OTP.GenEvent.Types
Compiling Data.Timeout
Compiling Control.OTP.Application.Behaviour
Compiling Control.Applicative
Compiling Control.Monad
Compiling Data.Time
Compiling Foreign
Compiling Control.Process
Compiling Control.OTP.Application.Types
Compiling Control.OTP.GenEvent
Compiling Control.OTP.GenEvent.Behaviour
Compiling Control.OTP.GenServer
Compiling Control.OTP.GenServer.Behaviour
Compiling Control.OTP.GenStatem
Compiling Control.OTP.GenStatem.Behaviour
Compiling Control.OTP.Supervisor.Behaviour
Compiling Control.OTP.Supervisor.Types
Compiling Database.Mnesia
Compiling ERTS.Counters
Compiling ERTS.Atomics
Compiling Data.Set
Compiling Data.PropList
Compiling Data.Float
Compiling Data.Binary
Compiling ERTS.PersistentTerm
Compiling System.Dir
Compiling System.IO
Compiling System.OS
Compiling System.Random
Compiling System.VM
Compiling Data.Maybe
Compiling Data.List
Compiling Data.Map
Compiling Data.Either
Compiling Control.OTP.Application
Compiling Data.String
Compiling Database.ETS
Compiling Env
Compiling Network.Socket
Compiling System.File
Compiling System.Init
Compiling Data.Result
Compiling System.Error
Compiling Data.Traversable
Compiling Prelude
Compiling Demo.GenServer
Compiling Control.OTP.Supervisor
verbus@ubuntu-s-4vcpu-8gb-nyc3-01:/hamler$ sudo make install/hamler$ sudo make install
[sudo] password for verbus:
STACK_YAML="stack.yaml" stack install --local-bin-path /usr/bin --allow-different-user
Getting project config file from STACK_YAML environment
Could not parse '/home/verbus/hamler/stack.yaml':
Aeson exception:
Error in $['extra-deps'][5]: failed to parse field 'extra-deps': expected PackageIdentifier, encountered Object
See http://docs.haskellstack.org/en/stable/yaml_configuration/
Makefile:18: recipe for target 'install' failed
make: *** [install] Error 1
verbus@ubuntu-s-4vcpu-8gb-nyc3-01:
STACK_YAML="stack.yaml" stack install --local-bin-path /usr/bin --allow-different-user
Getting project config file from STACK_YAML environment
Could not parse '/home/verbus/hamler/stack.yaml':
Aeson exception:
Error in $['extra-deps'][5]: failed to parse field 'extra-deps': expected PackageIdentifier, encountered Object
See http://docs.haskellstack.org/en/stable/yaml_configuration/
Makefile:18: recipe for target 'install' failed
make: *** [install] Error 1
make repl
to start the hamler interpreter:
> import Control.OTP.Application
> ensureStarted :sasl
Error found:
in module $PSCI
at :0:0 - 0:0 (line 0, column 0 - line 0, column 0)
Could not match type
String -> Atom
with type
Atom
while checking that type String -> Atom
is at least as general as type Atom
while checking that expression atom
has type Atom
in value declaration it
or to contribute content related to this error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.