elm - Elm 0.17 中的图像

标签 elm

我正在尝试使用单个图像的测试示例:

import Html exposing (Html)
import Graphics.Element
main = image 960 500 "starry-night.jpg"

我正在使用 elm-reactor 尝试这个,但这个简单的结果无法编译:

I cannot find module 'Graphics.Element'.

Module 'Main' is trying to import it.

Potential problems could be:
  * Misspelled the module name
  * Need to add a source directory or new dependency to elm-package.json

我尝试导入必要的图形包,evancz/elm-graphics

john@me:~/Documents/Elm$ cat elm-package.json

{
    "version": "1.0.0",
    "summary": "helpful summary of your project, less than 80 characters",
    "repository": "https://github.com/user/project.git",
    "license": "BSD3",
    "source-directories": [
        "."
    ],
    "exposed-modules": [],
    "dependencies": {
        "elm-lang/core": "4.0.1 <= v < 5.0.0",
        "elm-lang/html": "1.0.0 <= v < 2.0.0",
        "elm-lang/svg": "1.0.0 <= v < 2.0.0",
        "evancz/elm-graphics": "1.0.0 <= v < 2.0.0"
    },
    "elm-version": "0.17.0 <= v < 0.18.0"
}
<小时/>

我想出了:

import Html exposing (Html)
import Element exposing (image, toHtml)
main = toHtml ( image 960 500 "starry-night.jpg" )

最佳答案

模块的名称是 Element,而不是 Graphics.Element,因此编译器无法找到它。

此外,image 函数返回一个 Element,而 main 函数需要 Html 类型的内容.

程序的运行版本可能类似于

import Element exposing (..)

main =
    toHtml (image 960 500 "starry-night.jpg")

关于elm - Elm 0.17 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37512372/

相关文章:

elm - 如何访问 Elm 中的 Union 字段?

elm - 执行 elm-test 时无法编译下载的二进制文件

random - 在 Elm 中生成随机数所需的最少代码是多少?

elm - 在Elm 0.19中可扩展的记录是没有用的吗?

elm - Elm 中 Url.Parser.custom 的第一个参数

elm - Elm 中 Maybe a -> Svg Msg 类型的函数中没有 Nothing 时返回什么

elm - 在 Elm 中将整数数组解码为日期

elm - Elm 中未实现的 stub

debugging - 是否可以在使用 elm reactor 时显示 Elm 的调试器?

elm - Html.elm elm 0.18 中不允许使用单引号