haskell - 为什么我在 haskell 中查找时出现错误?
问题描述
我用 Haskell 中的查找编写了下面的代码:
justCheck :: a -> b -> Environment -> Bool
justCheck x y env = case lookup x env of
Just a -> find y env
Nothing -> error "Variable not found."
当我尝试运行代码时,在以下几行中出现“Normal”和“Just”错误:
Just a -> find y env
Nothing -> error "Variable not found."
方法 find 搜索列表 Environment 以查看 y 是否存在于其中,并且我没有得到任何错误。
数据类型 Environment 定义为 [(String,Int)]
谁能解释为什么我在这些行上出现错误?
编辑:
查找定义为:
find :: Int -> [(String, Int)] -> Bool
find y [] = error "Variable not found"
find y (x:xs) = if y == (snd x) then True else find y xs
解决方案
推荐阅读
- r - 为什么gganimate中的transition_layer要多加一层NA?可以去掉吗?
- python-3.x - 如何使用 if else 条件创建新列并在 Pandas 中用“Open Cases”和“Closed Cases”替换单词
- reactjs - 反应:在菜单标签内时复选框不更新
- r - 在R中提取国家名称
- python - 在单循环方法中测试一组节点的可用性
- c++ - 输入和输出迭代器是可交换的?
- javascript - encodeURIComponent 不对 HTML 数据属性中的换行符进行编码
- .net - dotnet 使用 ftp Github Actions 发布和部署
- javascript - AngularJS 的资源文件没有提供正确的编码字符串
- python - 正则表达式返回零长度匹配的标点符号?