在Haskell中“重复"吗? [英] 'Repeat' in Haskell?

查看:51
本文介绍了在Haskell中“重复"吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Haskell的新手,我有一个简单的问题.

I'm very new to Haskell, and I have a simple question.

我可以对a和b使用什么函数,这将导致a,b次.

What function can I use with a and b that will result in a, b times.

示例:
a = 4 |b = 3
将返回:
[4,4,4]

谢谢!

推荐答案

复制:

replicate 3 4

将是:

[4,4,4]


当您知道所需的函数的类型是什么(在这种情况下,很明显,所需的函数具有类似于 Int-> a-> [a] 的类型)),您可以使用 Hoogle 来找到它.


When you know what's the type of the function you need (in this case it was quite obvious that the function you needed had a type similar to Int -> a -> [a]) you can use Hoogle in order to find it.

这篇关于在Haskell中“重复"吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆