具有多参数函数的haskell中的点运算符 [英] Dot operator in haskell with multi-parameter functions
本文介绍了具有多参数函数的haskell中的点运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<$ c $我想在haskell中编写一个免费的函数,让事情变得简单可以说我想做这个函数: c> maxmin :: Ord a => a - > a - > a - > a
maxmin abc = max a(min bc)
我可以将此改进为 p>
maxmin ab =(max a)。 (min b)
但是有什么办法摆脱a和b吗?
解决方案
我不会说这是简单的,但在这里你去:
maxmin :: Ord a => a - > a - > a - > a
maxmin =(.min)。 (。)。最大
<生成于 pl
code> lambdabot http://www.haskell.org/haskellwiki/ Pointfree )
lambdabot> pl maxmin a b c = max a(min b c)
maxmin =(.min)。 (。)。最大
I want to write a function point-free in haskell, to keep things simple lets say I want to make this function:
maxmin :: Ord a => a -> a -> a -> a
maxmin a b c = max a (min b c)
I can improve this to
maxmin a b = (max a) . (min b)
but is there any way to get rid of a and b?
解决方案
I wouldn't say this is simplier but here you go:
maxmin :: Ord a => a -> a -> a -> a
maxmin = (. min) . (.) . max
(Generated with pl
tool from lambdabot
http://www.haskell.org/haskellwiki/Pointfree)
lambdabot> pl maxmin a b c = max a (min b c)
maxmin = (. min) . (.) . max
这篇关于具有多参数函数的haskell中的点运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文