当我向GHC提交代码时
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, ScopedTypeVariables #-}
class Modular s a | s -> a where modulus :: s -> a
newtype M s a = M {unM :: a} deriving (Eq, Show)
normalize :: (Modular s a, Integral a) => a -> M s a
normalize x :: M s a = M (x `mod` (modulus (undefined :: s)))
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
config1.hs:10:1: Parse error in pattern: normalize
Run Code Online (Sandbox Code Playgroud)
你能帮我吗?
Eric Macaulay
我有一个使用PHP 5语法的脚本,PHP 4中显然不支持这种语法.
喜欢MyClass :: method() - >方法(...)
我试图在脚本开头显示错误,告诉服务器没有安装PHP 5,并且很好地"死",但我不能,因为我得到了那个愚蠢的解析错误...
那么如果<5,我怎么能让PHP忽略错误呢?
我有一个类的以下简单代码,并从c = c ...if语句开始每行得到一个解析错误.另外我收到以下错误:
警告:类型与先前的隐式声明不匹配.函数isUpperCase中的isUpperCase的先前隐式声明:在'='标记之前解析错误.而且isLowerCase也有类似的错误.
有没有人有任何见解?
#include<stdio.h>
#include<string.h>
#define LOWERCASE_START = 97
#define LOWERCASE_END = 122
#define UPPERCASE_START = 65
#define UPPERCASE_END = 90
#define ALPHABET_LENGTH = 26
void simpleEncryption(char s[]){
int i;
for (i=0; i < strlen(s); i++){
char c = s[i];
if (isUpperCase(c) == 1){
c = c - UPPERCASE_START + 1;
c = c % ALPHABET_LENGTH;
c = c + UPPERCASE_START;
} else if (isLowerCase(c) == 1){
c = c - LOWERCASE_START + 1;
c …Run Code Online (Sandbox Code Playgroud) 这段代码:
validate :: Matrix-> Bool
validate x: [] = length x
validate x: xs = (length x == lenght.head $ xs) == (validate tail xs)
Run Code Online (Sandbox Code Playgroud)
产生此错误:
Parse error in pattern: validate
Run Code Online (Sandbox Code Playgroud)
为什么?
我的目标是,如果矩阵的格式正确,即所有行中的列数相等,则返回true,反之亦然.
执行99-Haskell问题的第三个(我目前正在尝试学习该语言)我尝试将模式匹配以及递归合并到我的函数中,现在看起来像这样:
myElementAt :: [a] -> Int -> a
myElementAt (x ++ xs) i =
if length (x ++ xs) == i && length xs == 1 then xs!!0
else myElementAt x i
Run Code Online (Sandbox Code Playgroud)
哪能给我Parse error in pattern: x ++ xs.问题:
注意:我知道这是一个非常糟糕的算法,但我自己设定了编写该函数的挑战,包括递归和模式匹配.我也试过不使用!!运算符,但这对我来说很好,因为它真正做的唯一事情(或者如果编译它应该做)是将单元素列表转换为该元素.
我找到了一些 Cloud Haskell 演示,并尝试运行它,但出现错误,但不知道为什么。错误看起来像:
MasterSlave.hs:18:9:模式中的解析错误:acc
MasterSlave.hs 的代码是:
module MasterSlave where
import Control.Monad
import Control.Distributed.Process
import Control.Distributed.Process.Closure
import PrimeFactors
slave :: (ProcessId, Integer) -> Process ()
slave (pid, n) = send pid (numPrimeFactors n)
remotable ['slave]
-- | Wait for n integers and sum them all up
sumIntegers :: Int -> Process Integer
sumIntegers = go 0
where
go :: Integer -> Int -> Process Integer
go !acc 0 = return acc
go !acc n = do
m <- expect
go …Run Code Online (Sandbox Code Playgroud) 我正在编写一个函数,将bool列表的列表无意义地映射到bool列表中.这是我的代码:
y=[False| y<-[0..]]
encode :: [[Bool]] -> [Bool]
encode x:xs = (zip1 x y):True:True:(encode xs)
encode []=[]
Run Code Online (Sandbox Code Playgroud)
zip1函数只需要两个列表并将它们交替写入新列表.
我收到错误消息
模式中的解析错误:编码
为什么我收到此错误消息?
我有一个获取列表并必须返回其最小元素的函数。
不幸的是,我一直遇到这个问题:
解析模式错误:最小
我做错了什么?
minim :: [Int] -> Int
minim [] = 0
minim [x] = x
minim x:xs = min x (minim xs)
min :: Int -> Int -> Int
min a b
| a > b = b
| a < b = a
Run Code Online (Sandbox Code Playgroud) recursion haskell functional-programming pattern-matching parse-error
我不明白为什么我会收到这个错误?这对我来说似乎是很好的语法。
$ for f in todo/family/* ; echo "$f" ; done
zsh: parse error near `done'
Run Code Online (Sandbox Code Playgroud)
第一个$是 PS1——这是在常规的“命令行”上——而不是在文件中。
我有一个函数,它返回从输入列表中找到的半个回文列表。如果我在一行上使用 if 语句但我想使用守卫,它会起作用。守卫给我一个解析错误。我阅读了很多给出这种错误的案例,但我没有弄清楚我的案例。这是代码:
palindromeHalfs :: [String] -> [String]
palindromeHalfs xs = map firstHalf (filter palindrome xs)
where
firstHalf :: String -> String
firstHalf ys | (length ys) `rem` 2 == 0 = take ((div (length ys 2)) ys
| otherwise = take ((div (length ys 2) + 1) ys
palindrome :: String -> Bool
palindrome str | str == reverse str = True
| otherwise = False
Run Code Online (Sandbox Code Playgroud)
和错误:
palindromeHalfs.hs:6:20: error: parse error on input `otherwise'
|
6 | | otherwise …Run Code Online (Sandbox Code Playgroud) parse-error ×10
haskell ×7
bash ×1
c ×1
command-line ×1
for-loop ×1
guard-clause ×1
php ×1
php4 ×1
recursion ×1
zsh ×1