Currently I'm learning Haskell and are stuck with the instantiation of types to typeclasses. I actually don't understand, why it's possible to create a value of the Maybe a type with Just (+).
The problem why this behaves strange to me is, that the Maybe type is defined as an instance of the Eq typeclass (see Haskell source) and that if you derive an instance for a type, all the fields of the value / data constructors of …
目前我正在尝试通过在线教程学习Haskell来学习Haskell.在"函数中的语法"一章中,作者写道"你也可以使用绑定到模式匹配的地方!".之后有一部分代码示例,但我不知道模式匹配与新的where绑定一起使用的位置.因为代码块的第一部分被缩短了("我们可以将我们之前函数的where部分重写为"),你只能推断它,但我认为我选择了正确的部分.
功能:
bmiTell :: (RealFloat a) => a -> a -> String
bmiTell weight height
| bmi <= skinny = "You're underweight, you emo, you!"
| bmi <= normal = "You're supposedly normal. Pffft, I bet you're ugly!"
| bmi <= fat = "You're fat! Lose some weight, fatty!"
| otherwise = "You're a whale, congratulations!"
where bmi = weight / height ^ 2
skinny = 18.5
normal = 25.0
fat = 30.0
Run Code Online (Sandbox Code Playgroud)
要替换的新where部分:
where bmi = weight …Run Code Online (Sandbox Code Playgroud) Currently I am trying to learn Haskell with the book 'Learn You a Haskell' and I'm trying to understand the implementations of the flip function in chapter 5. The problem is that the author states that if g x y = f y x is valid, then f y x = g x y must be also true. But how and why does this reversal affects the two function definitions?
I know how currying works and I also know …