简体   繁体   English

将3参数函数映射到Haskell中的列表

[英]Mapping 3 argument function to a list in Haskell

The map function works fine on really easy functions that take no arguments like *7 to every element in a list of Ints. map函数可以在非常简单的函数上正常工作,这些函数对Ints列表中的每个元素都不带* 7这样的参数。

But say I made a custom function that takes a Char, String and Int and then returns a Char and I wanted to apply this function to a list of Chars ie a String to get a String back after applying the other function to each Char? 但是说我做了一个自定义函数,该函数接受一个Char,String和Int,然后返回一个Char,我想将此函数应用于Chars列表,即在将另一个函数应用于每个Char之后将String返回到String? When I try this all I get is error messages? 当我尝试这样做时,我得到的只是错误消息?

Put your Char argument to the last position: 将您的Char参数放在最后一个位置:

foo :: String -> Int -> Char -> Char
foo str num c = c

bar = map (foo str num)

But we really need some more information from your side to help you better. 但是我们确实需要您提供更多信息,以帮助您更好。 Can you add the code you tried to write to your question? 您可以将尝试编写的代码添加到问题中吗?

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

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