elm / compiler Goto Github PK
View Code? Open in Web Editor NEWCompiler for Elm, a functional language for reliable webapps.
Home Page: https://elm-lang.org/
License: BSD 3-Clause "New" or "Revised" License
Compiler for Elm, a functional language for reliable webapps.
Home Page: https://elm-lang.org/
License: BSD 3-Clause "New" or "Revised" License
The cabal\Elm-0.6.0.1 directory contains elm-runtime-0.6.js.
But the compiler generates the following path:
(...)\cabal\Elm-0.6.0.1\elm-runtime-0.6.0.1.js
Running the server gives an error when I load up a .elm page:
Elm Server 0.3.5: running at <http://localhost:8000>
HTTP request failed with: shutdown: invalid argument (Socket is not connected)
main = asText 10.25
yields this error: Type error: Int is not equal to 111 -> 112
and
main = asText [ 11.5, 20, 21.1 ]
yields this error: Type error: Int is not equal to 125 -> 126
I think redrawing the image in canvas is what causes it.
Maybe a good solution would be to add a third function to go along with image
and fittedImage
. It would resize the image to fit within a bounding box while preserving aspect ratio, but not do any cropping (removing the need to redraw the image).
the ' symbol seems to make elm have a bad time
There is no unary (-) operator in Elm. I think you are aware of this (I saw usage of (0-1) in the examples) but I think it should be in the issues list for everyone to see and remember. I'll add this to my elm caveats list.
Parenthesised use of infix operators is confusing for first timers. Add explanation!
I had a relatively old version of shakespeare installed, 0.10.2
. Upgrading to Elm 0.4.0
failed with the following:
src/Language/Elm/Quasi.hs:93:5:
Not in scope: `shakespeareFileReload'
Upon upgrading shakespeare to 1.0.1.3
, Elm installed with no fuss.
compiler fail
The Elm Compiler 0.5.0.2
Pong is at 87eaa91
Error while compiling Pong.elm: Parse error at (line 100, column 5): unexpected "U" expecting "{"
bug observed long time ago, just never reported. It happens on various configuration (school, home,..).
I already saw this on an other project (not elm-related) where someone fixed it by I don't know which trick (yeah, cool story). The point is that there should be a way to deal with this problem which is visible in a fairly large number of pc.
As usual, thanks very much for making elm. :)
http://jshaskell.blogspot.fr/2012/11/breakout-improved-and-with-netwire.html
Look at this beautifull piece of code.
Do you think Elm will achieve similar expressivity ?
( And can't google hire a other guy to help out with parsers and stuff ?
I'm really waiting forward the time this langage will mature)
Thanks! :)
I'm really enjoying the work you've done! Being able to sidestep the whole html/js hairball and encapsulate your app entirely in an .elm file is very cool.
One thing that caught me by surprise is the way the html file produced by elm references your local copy of the elm runtime (in my case, deep in my .cabal folder). That means you can't just throw the html file up on a server, or serve your project folder locally with something like python -m SimpleHTTPServer
.
I see that there's a switch to let you specify your own path to the runtime, but it would also be nice to have a compiler switch that embeds the whole thing into the html, so it's completely self-contained. It might not be appropriate for larger apps, but for small stuff it would be very handy.
I threw together the following:
background(width, height) = collage width height [ filled black (rect width height (0, 0)) ]
main = lift background Window.dimensions
My handle on the syntax is pretty shaky, but I expected the above pair of lines to cause a solid black collage to fill the browser window. It didn't, only going to about 50% (Chromium 18.0 on Ubuntu 12.04). Apologies if this is just a mistake on my part!
Please help me with installing Elm on Fedora 17. I'm not very familiar with ghc and cabal. I tried installing the ghc and cabal packages provided by the Fedora repositories. Unfortunately they seem to be too old, it seems to be 2011.4.0.0-6.
Is there any way to update my ghc installation?
Are there any Fedora users here?
To be able to make images clickables, for instance
Possible solutions:
browser version: 7.0.5730.13CO
Maybe because of window.getComputedStyle, called after Value.getTextSize().
This is the workaround.
http://snipplr.com/view/13523/
I was expecting the result of findArray "foo" json
to act like a list. It does sometimes, but not in all instances, leading to some confusing situations.
For instance, this doesn't work:
json = extract res
children = (findArray "children" . findObject "data") json
urls = map (findString "url" . findObject "data") children
urls ends up as a list of empty lists.
It seems the only way to get at the contents of the list in children
is by destructuring, as in the flickr search demo. Other list operations like head children
don't work either.
In the update log for 0.6 you stated that tuples are now comperable, but this code:
main = asText $ (1,2) < (1,1)
gives an error:
Type error: (t613,t615) is not a {Char,Date,Float,Int,String} in context `(Tuple2 1) 2' in main
http://elm-lang.org/misc/Pong.html
gives a
Server error: public//misc/Pong.html: openFile: does not exist (No such file or directory)
To allow existing css to be used.
It would be nice to have a complete wrapper for background properties of elements,
http://www.heroku.com/ shows what kind of background I'd like to build. (picture repeating horizontally)
I couldn't find it in the website?
As a driving example, the Dict class doesn't make sense without typeclasses. Right now, it's unclear how exactly the Dict implementation gets the "compare" function - it looks like duck typing.
Without type classes, passing in an Ord instance is preferable to duck typing.
e.g.
instead of:
singleton :: k -> v -> Dict k v
do this:
data Ordering = LT | EQ | GT
data Ord a = Ord (a -> Ordering)
singleton :: Ord k -> k -> v -> Dict k v
Alternatives include generalised implicit parameters.
I think, given Elm's Haskell heritage, Haskell-style type classes would be nice.
http://elm-lang.org/edit/examples/JavaScript/ZipCodes.elm
I get a compile error in Firefox 16 and Chrome 22. Mac OS X 10.8:
Your browser may not be supported. Are you using a modern browser?
Runtime Error in Main module:
TypeError: undefined is not a function
The problem may stem from an improper usage of:
Success, findWithDefault, fromString, gets
System properties:
I've attempted the first few steps of installing elm, and encountered the following error when running cabal install elm
:
cabal: cannot configure happstack-server-7.0.2. It requires blaze-html ==0.5.*
For the dependency on blaze-html ==0.5.* there are these packages:
blaze-html-0.5.0.0. However none of them are available.
blaze-html-0.5.0.0 was excluded because Elm-0.1.0 requires blaze-html ==0.4.*
I then tried installing blaze-html directly, but that resulted in its own set of failures.
If it's not possible to solve these dependency issues, at least a note in the README for Mac OSX users would be good to have.
The website http://elm-lang.org does not work on the xulrunner based conkeror
(http://www.conkeror.org/) browser. Instead of showing the actual content the
website presents the user with the following error message:
"An Error Occured: Better Messages to come."
conkeror version: 1.0pre (commit
e4c6bf10ad882c623ebccf3937ac44bf79abc432)
xulrunner version: 1.9.2.17
OS: Ubuntu 11.10/12.04
Javascript console output:
Error: uncaught exception: [Exception... "Not enough arguments" nsresult: "0x80570001 (NS_ERROR_XPC_NOT_ENOUGH_ARGS)" location: "JS frame :: http://elm-lang.org/elm-mini.js :: anonymous :: line 5" data: no]
Error: document.getElementById("widthChecker") is null
Source File: http://elm-lang.org/elm-mini.js
Line: 26
import Input
import Color
(a,b) = textField "trololo"
main = flow down [plainText "test", color red a,a,a,a,a,plainText "test"]
gives a surprising result
Elm does not seem to have a built-in function for converting a string to a number. I don't think it has a function for converting a number to a string, either (e.g. plainText $ show n ++ " bottles of beer on the wall"
).
To address the former, we could add the following functions, perhaps to Prelude, Foreign.JavaScript, or even a new "Numeric" module.
parseInt :: String -> Maybe Int
parseIntBase :: Int -> String -> Maybe Int
parseFloat :: String -> Maybe Float
Here is the corresponding JavaScript. We must be careful not to shadow the system parseInt
and parseFloat
when defining our functions.
function parseIntBase(base) {
return function(str) {
var n = parseInt(castStringToJSString(str), base);
return isNaN(n) ? Nothing : Just(n);
};
}
...
return {
parseInt: parseIntBase(10),
parseIntBase: parseIntBase,
parseFloat: function(str) {
var n = parseFloat(castStringToJSString(str));
return isNaN(n) ? Nothing : Just(n);
}
};
Would something like this be good? Or did you have bigger plans, like a read
function whose return type determines behavior.
I was playing around in elm-lang.org's interactive IDE, trying to make a draggable circle. In particular, I was going for something like this:
dragCircle :: Number -> (Number, Number) -> DragCircle
type DragCircle = (Form, (Number, Number) -> Bool -> DragCircle)
-- note the infinite type
Then, use foldp
and lift2 (,) position isDown
to feed the DragCircle
automaton.
I ended up crashing the server. I compiled elm-server locally and reproduced the hang and leak. Here's a minimal code sample triggering the leak:
move pos down = rest
rest pos down = if down then move else rest
I suppose such hangs could be avoided using System.Timeout in elm-server, e.g.:
mhtml <- liftIO . timeout 10000000 . evaluate $ Elm.toHtml libLoc (pageTitle filePath) content
I don't know if happstack-server does anything to time out response generation or not.
Another thing you could do is set the maximum amount of memory the runtime system may allocate, by adding this to the .cabal file:
ghc-options: -rtsopts -with-rtsopts=-M512m
This way, if elm-server blows up again, it doesn't bring the whole system to a crawl.
Elm currently does not let you set the thickness of a line. Actually, you can make thick lines using scale
, but you have to tweak your coordinates.
I suppose the API could be this:
thickness :: Number -> Form -> Form
This would set the thickness of lines, both for polygon edges (coming from Shape) and line paths (coming from Line).
While we're at it, it would be nice if line
and segment
returned a Form
instead of a Line
. It's annoying to have to specify the style and color of a line just to get it on the page:
main = collage 500 500
[ solid black $ segment (0,0) (100, 100)
]
I'd rather just say:
main = collage 500 500
[ segment (0,0) (100, 100)
]
and have it default to a solid black line.
I would tackle this, but Element.js looks like it came from a code generator. Do you have the original Elm source, or do you just tweak the generated code now?
I wanted to use some point-free style in Elm and I wrote this little function:
cell = ((filled (rgb 64 64 64) .) .) . rect
Unfortunately running this code results in a parsing error.
I made a few additional tests to learn more about what is happening:
comp f g = \x -> f (g x)
cell = ((filled (rgb 64 64 64) `comp`) `comp`) . rect
This still doesn't work, but the one below is fine:
cell = (comp (comp (filled (rgb 64 64 64)))) `comp` rect
I think there's a little syntax issue here involving infix operators.
On a side note - is there any documentation on Elm syntax?
I ran into some show-stopping bugs in the module system of Elm 0.4.0.1:
Modules do not export anything by default, contrary to the Elm 0.3 announcement. Saying module Foo where
does not export any functions, whereas module Foo (foo) where
does.
The module Foo (ADT(..))
syntax is not supported. Instead, one must say module Foo (ADT, A, B)
, where A and B are the data constructors. This is unintuitive for someone used to Haskell.
Importing some system modules doesn't work when building with --make. If I import Graphics.Element
, I get:
elm: Graphics/Element.elm: openFile: does not exist (No such file or directory)
However, import Signal.Mouse
does work.
The first two issues are annoying, but make the module system unusable to one who doesn't know the workarounds. The third issue is more serious, since it means an application divided into modules loses access to a lot of good functionality (unless there's some tricky command to import Graphics/Element.js directly)
These issues should be easy to reproduce using elm --make
. If they aren't, let me know.
problem is:
how do I write my name: "Rémi" ?
I can't do main = plainText "Rémi" since the output is "Rmi" (é is removed automatically)
Can you give me an example of how to do display a random number on the screen?
(I know this is not an issue. I am just trying to understand)
-Thanks
Drew
480-840-5406
1:
layers :: [Element] -> Element
Stack elements on top of each other. -> in which order ? :)
2:
please, tell us type of 'main' function: Either element or signal element, this is super annoying when you take a look at elm for the first time.
3:
Could you add in the doc that Form is actually Canvas ?
Why not to use CanvasForm?
4: can you explicit what those two first 'int' in definition are in the doc?
container :: Int -> Int -> Position -> Element -> Element
Put an element in a container.
Sript debugging screenshot on IE9:
Later the script is stopped at this breakpoint:
catch (e) {Elm.main=function() {var msg = ('<br/><h2>Your browser may not be supported. Are you using a modern browser?</h2>'
+ '<br/><span style="color:grey">Runtime Error in Main module:<br/>' + e
+ '<br/><br/>The problem may stem from an improper usage of:<br/>skeleton</span>');document.body.innerHTML
= Text.monospace(msg);throw e;};}</script><script type="text/javascript">Dispatcher.initialize()<
Strange thought about this request.
basically, this can't wok well :
(a, position) = withPositionEvent (plainText "test")
main = flow down [a,a,a,a] -- incoherent meaning of position :/, and no way to define hover signal too on previous line
but I would like to be able to write something lke this :
posOfThirdA = SignalThatWillBeDefinedLaterWithDefault (0,0)
a = plainText "test"
main = flow down [a,a,withPositionEvent posOfThirdA a,a, asText posOfThirdA ]
I wans't able to find a way to do so in the doc
and it's not just me: http://www.downforeveryoneorjustme.com/elm-lang.org
Just in case you didn't know about it. Cool project, BTW.
$ cabal install elm
Warning: Falling back to topdown solver for GHC < 7.
Resolving dependencies...
cabal: dependencies conflict: base-3.0.3.2 requires an installed instance of
syb ==0.1.0.2 however:
The output is truncated, so maybe this is actually a cabal bug?
If Elm needs a newer GHC it should mention it on the installation page.
Running this sample code on elm 0.6.0.2:
import Dict
dict = fromList [(1,2),(2,3)]
main = asText $ values dict
gives me an error:
ReferenceError: List is not defined
Quick glance into the js console indicates that is has something to do with List namespace in Dict implementation.
I think that we need to find a way to do regression tests for Elm as fast as possible:)
toForm :: (Number,Number) -> Element -> Form
Turn any Element into a Form
There is no way to find out that the middle of the element will be placed at Number, Number
except trial and error or examples.
also, wouldn't it be better to put the corner at (Number, Number) ?
Since 0.5.0.2 Elm.cabal has introduced an upper version limit on pandoc (<=1.9.4.2)
The commit: 3bbb984
The problem is you can't install both Elm-0.5.0.2 (which requires base64-bytestring-0.1.2.0)
and elm-yesod-0.1.3 + yesod-platform-1.1.5 (requires base64-bytestring-1.0.0.0)
p.s.
As a workaround i stick to Elm-0.5.0.1 which doesn't limit the pandoc's upper version.
(Still elm-yesod-0.1.3 won't compile, but this is a topic for another issue: tazjin/elm-yesod#2)
The following program does not work in Elm 0.6:
main = asText (readFloat "1")
Runtime Error in Main module:
ReferenceError: Char is not defined
readInt does not work either
The issue is that the String.js code creates a var String, which is captured by Elm.Char in place of the builtin String. I first noticed this because the Key Presses example is broken.
I have fixed it by capturing String by reference, before it is replaced, as below, but this will not work if code is reordered.
Elm.Char = function(String) {
// Elm.Char
}(String);
Other solutions might be Elm's namespacing String or adding fromCharCode to it, but since I've been looking at Elm for all of half an hour, I'll leave you without a recommendation.
foldr1
uses the first item instead of the last item for the base case. For example:
main = plainText $ foldr1 (++) ["1", "2", "3", "4", "5"]
displays:
23451
This is surprising behavior, and contrary to Haskell's foldr1
:
> foldr1 (++) ["1", "2", "3", "4", "5"]
"12345"
To make something like in http://www.heroku.com/ when we click in papers folded.
trigger a click event from any element,
that may be a bit similar to hover and position signals requests
Hi,
This is not working :
container 900 200 (middleAt (relative 0.5) (relative 0.5) ) (plainText "test")
but this is working;
container 900 200 (topLeftAt (relative 0.5) (relative 0.5) ) (plainText "test")
message from chrome
Uncaught ReferenceError: elem is not defined (message from chrome)
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.