我将如何为下面的代码片段应用类型注释?注意:e 和 r 是列表树的。
let
{--what is the type annotation here for the tuple (e, r)?--}
( e, r ) = List.partition (\(Node a _) -> a == (toString c)) lt
in....
Run Code Online (Sandbox Code Playgroud) 我想看看给定列表的长度是否等于某个数字。但是==期望两个数字不是 Int,所以即使我输入(==) 1type 仍然number -> Bool是最后当我输入结果时lenght我得到编译错误:
- 类型不匹配 - - - - - - - - - - - - - - - - - - - - - - - ------------ REPL
此函数无法处理通过
(|>)管道发送的参数:Run Code Online (Sandbox Code Playgroud)4| List.length |> ((==) 1) ^^^^^^论据是:
Run Code Online (Sandbox Code Playgroud)List a -> Int但是
(|>)正在将它传递给一个期望的函数:Run Code Online (Sandbox Code Playgroud)number提示:只有 Int 和 Float 值可以用作数字。
那么如何指定我的常量是一个 Int 而不是 number 变量呢?
Elm 新手可以帮助我理解为什么此代码返回我的错误“无法加载页面”?我很确定这与返回的 JSON 数据有关,我还没有弄清楚如何管理它。
基本上我是 Elm 的新手,并希望通过使用来自免费 API 的更多 JSON 数据来更进一步,任何人都可以伸出援手吗?
import Browser
import Html exposing (Html, text, pre)
import Http
-- MAIN
main =
Browser.element
{ init = init
, update = update
, subscriptions = subscriptions
, view = view
}
-- MODEL
type Model
= Failure
| Loading
| Success String
init : () -> (Model, Cmd Msg)
init _ =
( Loading
, Http.get
{ url = "http://api.openweathermap.org/data/2.5/weather?q=naples&APPID=mykey"
, expect = Http.expectString GotText
}
)
-- …Run Code Online (Sandbox Code Playgroud) 当我尝试|>在 elm 中使用运算符时出现错误
kl : List Float
kl =
List.map toFloat (List.range 1 10)
Run Code Online (Sandbox Code Playgroud)
kll : Float
kll =
let
half x =
x / 2
in
List.sum (List.map half (List.map toFloat (List.range 1 10)))
Run Code Online (Sandbox Code Playgroud)
下面的代码我使用|>并得到一个错误:
klpipe : List Float
klpipe =
1 10 |> List.range |> toFloat |> List.map
Run Code Online (Sandbox Code Playgroud) 在过去的几年里,我一直关注 Elm 的开发,终于有机会使用 Elm 进行 POC!我似乎记得这hiding是一种导入模块中除hiding ()列表中列出的之外的所有函数/类型的方法。
那个功能被删除了?我试图寻找答案,但一直找不到。