English 中文(简体)
表达式上下文中的 Haskell - 模式语法: _
原标题:Haskell- Pattern syntax in expression context: _

我一直在学习一些哈斯凯尔(Haskell)程序, 并写一些非常简单的程序。 我想做一个功能, 返回给定位置的元素 。 以下是我试图做的...

elempos::Int->[a]->a
elempos n (b:_)=head (drop n (b:_) )

但是当我在GHCi编辑器上加载测试.hs文件时,我就会发现这个错误。

Pattern syntax in expression context: _

And it says Failed, modules loaded:none. Since I m very new to the language I don t really have a proper idea what the mistake is(currently at chapter 4 of learn you a haskell). Can anyone tell me what is wrong here?

最佳回答

只有内部模式才有效, 您正试图在表达式中使用它 : head (drop n (b:_)) 。 由于您不需要对列表进行分解, 您需要尾巴, 解决方案是 :

elempos n xs = head (drop n xs)
问题回答

暂无回答




相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

pdo database abstraction

Can someone help me to see what is going wrong with this setup I build the @sql query in the function below like this. The extra quotes are setup in the conditions array. $sql .= " WHERE $...

I wish I could correlate an "inline view"

I have a Patient table: PatientId Admitted --------- --------------- 1 d/m/yy hh:mm:ss 2 d/m/yy hh:mm:ss 3 d/m/yy hh:mm:ss I have a PatientMeasurement table (0 to ...

Syntax help! Php and MYSQL

Original: $sql = "SELECT DATE(TimeAdded) AS Date, $column_name FROM Codes ORDER BY TimeAdded ASC"; Altered: $sql = "SELECT DATE("m", TimeAdded ) AS Date, ColumnName FROM TableName ORDER BY ...

Is this code Equivalent

I am not a fan of the following construction if (self = [super init]) { //do something with self assuming it has been created } Is the following equivalent? self = [super init]; if (self != ...