2017-01-29 64 views
0

我定义我的模型是Model = Dict Int String然而,在编译时使用诠释或数字,我得到number代替Int所以它是错误的:在榆树字典

The 2nd argument to function `get` is causing a mismatch. 

71|    Dict.get 3 model 
          ^^^^^ 
Function `get` is expecting the 2nd argument to be: 

    Dict number v 

But it is: 

    Model 

,不幸的是榆树REPL不返回Dict number同样的事情而不是Dict Int

> Dict.fromList [ (1, {a= 1})] 
Dict.fromList [(1,{ a = 1 })] : Dict.Dict number { a : number1 } 

某些语言如Haskell中暴露Int作为以及Integer以及number我怎么能强迫它是整数?

回答

4

你能提供相关的代码吗?

下面的编译和我工作得很好:

import Dict exposing (Dict, fromList, get) 

type alias Model = Dict Int String 

model : Model 
model = fromList [(1, "apple"), (2, "banana"), (42, "giraffe")] 

test : Maybe String 
test = get 2 model 
+1

我需要向下收缩我的代码到SCCCE例如http://sscce.org –

+2

上述答案的重要组成部分是,'货号'被定义为一个'Dict'别名。 请确保您的模型定义使用'alias'关键字。否则,您将您的模型定义为单个案例区分联盟。 'type alias Model = Dict Int String' – Adrian