Haskell中的运行时错误 [英] runtime error in Haskell

查看:168
本文介绍了Haskell中的运行时错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的程序是在元组列表中搜索<​​/ strong>我将它写成如下

  import List 
data BookInfo = Book Int String [String]
deriving(Show)

enter :: Int-> String-> [String] - > BookInfo
输入id名称subject = Book id名称subject
bookId(Book id __)= id

index :: BookInfo - > Int
index(Book id name subject)= bookId(Book id name subject)

arrayentering :: BookInfo-> [BookInfo] - > [BookInfo]
arrayentering(本书编号名称主题)[] = [(书目编号名称主题)]
arrayentering(Book _[])[] = []
arrayentering(Book id name subject)[ (Book id name subject):[(Book it name suject)]
toList :: [BookInfo] - > [Int]
toList [(Book id名称主题)] =地图索引[(书名ID主题)]

bubbleSort::( Ord t)=>如果x else y:[t] - > [t]
bubbleSort [x,y,z,xs] =
[ x,z,xs]

superBubble::( Ord t)=> [[t]] - > [[t]]
superBubble a =地图bubbleSort a

合并:: [BookInfo] - > [[Int]]
合并[(Book id name subject)] = superBubble [toList [(Book id name subject)]]

并清除它从任何语法错误,但在我尝试进入一个元组清单组合()它给我运行时错误说



例外:在函数Main.combining中没有详尽的模式



这是什么意思? / p>

请给我说明。如果可能的话,我想自己修复它。



 结合[(Book id name subject)] = superBubble [toList [(Book id name subject)]] 

仅与仅包含一个元素的列表匹配。在 bubbleSort 中有类似的问题,其中

  bubbleSort [x, y,z,xs] = 

仅匹配包含四个元素和其他地方的列表。



我还没有弄清楚你打算如何工作,或许使用了一个变量模式(匹配所有参数)

 合并books = superBubble(toList books)

会是合适的吗?




我怀疑

  arrayentering :: BookInfo-> [BookInfo]  - > [BookInfo] 
arrayentering(Book id name subject)[] = [(Book id name subject)]
arrayentering(Book _ [书籍编号名称主题] [(Book it namr suject)] =
(书目编号名称主题):[(Book it name suject)]

实际上应该是

  arrayentering book bookList 
|空书= bookList
|否则= book:bookList
其中
空(Book _ name subject)= all是空格名称&& all(all isSpace)subject

empty 可能是错误的)。



toList 应该只是 map index


My program is searching in list of tuples I wrote it as the following

import List
data BookInfo = Book Int String [String]
  deriving(Show)

enter :: Int->String->[String]->BookInfo
enter id name subject=Book id name subject
bookId   (Book id _     _  ) = id

index :: BookInfo -> Int
index (Book id name subject) =  bookId  (Book id name subject) 

arrayentering ::BookInfo->[BookInfo]->[BookInfo]
arrayentering (Book id name subject) [] =[(Book id name subject)]
arrayentering (Book  _  "     " ["    "]) [] =[]
arrayentering (Book id name subject) [(Book it namr suject)]=                         
              (Book id name subject):[(Book it name suject)]
toList::[BookInfo]->[Int]
toList [(Book id name subject) ]=   map index [ (Book id name subject)]

bubbleSort::(Ord t) => [t]->[t]
bubbleSort[x,y,z,xs]=
                if x<y then x : [y,z,xs]
                       else y : [x,z,xs]

superBubble::(Ord t) => [[t]]->[[t]]
superBubble a=map bubbleSort a

combining::[BookInfo]->[[Int]]
combining [(Book id name subject)]=superBubble [toList [(Book id name subject)]]

and clean it from any syntax error but after i try to enter to a list of tuple to combining() it gve me runtime error say

Exception:Not Exhaustive pattern in function Main.combining

What does this mean?

Please, give me only instructions. If possible, I would like to fix it by my self.

解决方案

The pattern in the function definition

combining [(Book id name subject)]=superBubble [toList [(Book id name subject)]]

matches only lists with exactly one element. You have a similar problem in bubbleSort, where

bubbleSort[x,y,z,xs]=

matches only lists with exactly four elements and elsewhere.

I haven't figured out how you intend it to work, perhaps using a variable pattern (that matches all arguments)

combining books = superBubble (toList books)

would be appropriate?


I suspect

arrayentering ::BookInfo->[BookInfo]->[BookInfo]
arrayentering (Book id name subject) [] =[(Book id name subject)]
arrayentering (Book  _  "     " ["    "]) [] =[]
arrayentering (Book id name subject) [(Book it namr suject)]=                         
              (Book id name subject):[(Book it name suject)]

should really be

arrayentering book bookList
    | empty book = bookList
    | otherwise  = book : bookList
      where
        empty (Book _ name subject) = all isSpace name && all (all isSpace) subject

(empty may be wrong).

And toList should probably be just map index.

这篇关于Haskell中的运行时错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆