小编Cha*_*ert的帖子

我可以在类型名称上模式匹配吗?

是否可以在类型名称本身而不是在类型的构造函数上进行模式匹配?

这是一个人为的例子,代码不能编译,我希望解释我在追求的内容:

what :: a -> String
what (x :: String) = "It's a String!"
what (x :: Int) = "It's an Int!"
what x = "Not sure what it is."
Run Code Online (Sandbox Code Playgroud)

haskell

1
推荐指数
2
解决办法
101
查看次数

如何在elm中的case语句中获取字符串的值

考虑以下.为什么它不起作用.我怎么能让它发挥作用?

type IntOrString
  = String
  | Int

getInt : IntOrString -> String
getInt intOrString =
  case intOrString of
    String ->
      intOrString

    Int ->
      toString intOrString
Run Code Online (Sandbox Code Playgroud)

elm

1
推荐指数
1
解决办法
285
查看次数

为什么网站默认不默认为index.html?

我无法输入域名来观察登录页面:

http://some_url.com
Run Code Online (Sandbox Code Playgroud)

错误:

找不到文件'E:\ index.html'.

但是,以下工作:

http://some_url.com/index.html

仅供参考:本网站由Elm,Giraffe和.Net Core构建.

f# elm .net-core asp.net-core

1
推荐指数
1
解决办法
147
查看次数

从Haskell中的String中剪切前x个字符

我正在尝试创建一个将列表中的部分字符串连接到另一个字符串的函数.我已经知道如何选择我想要的字符串,但现在我需要它们的第一部分(并且它并不总是相同的值).

所以我想剪掉一个字符串的第一部分

-- here is a function who should take a string and the numbers
-- of characters we want to take from the start
cutString :: Int -> String -> String
cutString x str = cut x str -- here's a way to take the first x characters
Run Code Online (Sandbox Code Playgroud)

以及使用它的方式:

print (cutString 3 "Hello World")
Output --> "Hel"
Run Code Online (Sandbox Code Playgroud)

有没有简单的方法可以做到这一点?

感谢您提供任何帮助或建议.

string haskell

1
推荐指数
1
解决办法
1148
查看次数

标签 统计

elm ×2

haskell ×2

.net-core ×1

asp.net-core ×1

f# ×1

string ×1