Haskell跟踪函数组合吗? [英] Does haskell keep track of function composition?

查看:106
本文介绍了Haskell跟踪函数组合吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想知道Haskell是否跟踪天气函数是一个函数组合,也就是说我可以定义一个类似于这个函数的函数吗?

  compositionSplit fg =(f,g)


解决方案

不,这是不可能的。



例如,

  f1 =(+ 1)。 (+ 1):: Int  - > Int 



  f2 =减1。 (+ 3):: Int  - > Int 

和参照透明度要求等于可以代替等于,所以如果 compositionSplit 是可能的,它会产生相同的结果 f1


  • / code>和 f2 ,因为它是相同的函数,但是
  • compositionSplit f1 = ((+ 1),(+1)) compositionSplit f2 =(subtract 1,(+ 3)) compositionSplit


I was wondering if Haskell keeps track of weather a function is a function composition, i.e would it be possible for me to define a function that does something similar to this?:

compositionSplit f.g = (f,g)

解决方案

No, it wouldn't be possible.

For example,

f1 = (+ 1) . (+ 1) :: Int -> Int

is the same function as

f2 = subtract 1 . (+ 3) :: Int -> Int

and referential transparency demands that equals can be substituted for equals, so if compositionSplit were possible, it would

  • need to produce the same result for f1 and f2, since that is the same function, yet
  • compositionSplit f1 = ((+ 1), (+1)) and compositionSplit f2 = (subtract 1, (+ 3)) would be required by the specification of compositionSplit.

这篇关于Haskell跟踪函数组合吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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