IDRIS不减少地图查找

时间:2019-01-19 02:04:58

标签: idris

为什么不减少函数调用?如何在编译时验证映射是否包含键值对?

import Data.SortedMap

N : SortedMap String Type
N = fromList
    [ ("a", Nat)
    , ("b", String)
    ]

t : lookup "a" N = Just Nat
t = Refl

Type mismatch between
        Just Nat = Just Nat (Type of Refl)
and
        lookup "a" (fromList [("a", Nat), ("b", String)]) = Just Nat (Expected type)

Specifically:
        Type mismatch between
                Just Nat
        and
                lookup "a" (fromList [("a", Nat), ("b", String)])

1 个答案:

答案 0 :(得分:2)

它必须与SortedMap的实现有关,因为使用普通List的版本可以按预期工作:

N : List (String, Type)
N =
    [ ("a", Nat)
    , ("b", String)
    ]

t : lookup "a" N = Just Nat
t = Refl

根据文档Data.SortedMap.lookup也是合计的,因此应减少。也许原因是SortedMap中的函数和数据类型似乎具有导出限定符,而Data.List中的函数和数据类型使用了public export