简体   繁体   English

干净-附加到列表

[英]Clean - Appending to a list

I am trying to append to a list in the Clean programming language . 我试图将其附加到Clean编程语言的列表中。

This is my code: 这是我的代码:

import StdEnv

path0 = "urrd"
//path1 = "urdl"
//path2 = "uurrddll"
//path3 = "ururdrdldlul"

Mirror :: [Char] -> [Char]

Mirror [] = []
Mirror str = [(NegatePath last str) : (Mirror init str)]

NegatePath :: Char -> Char

NegatePath 'u' = 'd'
NegatePath 'd' = 'u'
NegatePath 'l' = 'r'
NegatePath 'r' = 'l'

Start = Mirror path0

This is the error I get: 这是我得到的错误:

Type error [Homokozoo.icl,13,Mirror]:"argument 1 of list constructor" cannot unify types: [Char] {#Char} 类型错误[Homokozoo.icl,13,Mirror]:“列表构造函数的参数1”无法统一类型​​:[Char] {#Char}

I didn't know about the Clean language before reading this question, so this could be way off, but I think I've identified the problem after spending some time scanning chapter 4 of the language report. 在阅读此问题之前,我不了解“干净”语言,因此可能还很遥远,但是我认为在花了一些时间阅读该语言报告的第4章之后,我已经确定了问题所在。 The problem appears to be that your Mirror function is built to operate on a list of characters [Char] but you are passing it an unboxed array of characters {#Char} . 问题似乎是您的Mirror函数是为在字符列表[Char]上运行而构建的,但是您正在向其传递未装箱的字符{#Char}数组。

It might work if you declared 如果您声明,它可能会起作用

path0 = ['urrd']

so that the type of path0 is a list of characters rather than an unboxed array of characters. 因此path0的类型是一个字符列表,而不是未装箱的字符数组。 If that's not what you want, you may need to modify the Mirror function to work on {Char} . 如果这不是您想要的,则可能需要修改Mirror函数以在{Char}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM