2017-01-29 68 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