Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/haskell/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Variables Haskell:用变量名替换字符_Variables_Haskell - Fatal编程技术网

Variables Haskell:用变量名替换字符

Variables Haskell:用变量名替换字符,variables,haskell,Variables,Haskell,我想在这里执行类似我的工作: hashTag :: Char hashTag = "#" 因此,我可以稍后参考: 例如,将#添加到列表或稍后分配 Point::Int -> Int -> Point -> String Point a b x | firstPoint(x) == a && secondPoint(x) == b = "#" | otherwise = "." hashTag

我想在这里执行类似我的工作:

hashTag :: Char
hashTag = "#"
因此,我可以稍后参考: 例如,将#添加到列表或稍后分配

Point::Int -> Int -> Point -> String
Point a b x
  | firstPoint(x) == a && secondPoint(x) == b = "#"
  | otherwise = "."

hashTag
有一个问题,您将其定义为
Char
,但您编写了一个字符串文本。您可以使用字符文本,也可以将
标签的类型更改为
字符串

如果我们将类型更改为
字符串
,我们可以使用:

hashTag :: String
hashTag = "#"
然后,您需要将其包装在一个列表中,以生成一个带有单个字符的
字符串:
hashTag

Point :: Int -> Int -> Point -> String
Point a b x
  | firstPoint x == a && secondPoint x == b = [hashTag]
  | otherwise = "."
Point::Int->Int->Point->String
a点b点x
|第一个点x==a&&secondPoint x==b=[hashTag]

|否则,“.”
那么你的问题是什么?你可以简单地使用
第一点(x)==a&&secondPoint(x)==b=hashTag
hashTag :: Char
hashTag = '#'
Point :: Int -> Int -> Point -> String
Point a b x
  | firstPoint x == a && secondPoint x == b = [hashTag]
  | otherwise = "."