2016-05-29 53 views
3

我試圖試驗例用單個圖像:圖像0​​.17

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

我想這一點與榆樹反應器和這個簡單的結果不編譯:

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 

我試圖導入必要grahics包,evancz/elm-graphics

[email protected]:~/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") 

回答

3

模塊的名稱是Element,不Graphics.Element,所以這就是爲什麼編譯器無法找到它。

此外,image函數返回一個Element,而main函數期望的Html類型的東西。

程序的運行版本可以像

import Element exposing (..) 

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