PythonとRuby(そして他の人もそうだと思います)。列挙可能ファイルの前に*
( "splat")を付けて、引数リストとして使用できます。たとえば、Pythonでは次のようになります。
>>> def foo(a,b): return a + b
>>> foo(1,2)
3
>>> tup = (1,2)
>>> foo(*tup)
3
Haskellに似たようなものはありますか?リストの長さは任意であるため、リストでは機能しないと思いますが、タプルでは機能するはずだと思います。これが私が欲しいものの例です:
ghci> let f a b = a + b
ghci> :t f
f :: Num a => a -> a -> a
ghci> f 1 2
3
ghci> let tuple = (1,2)
私は私がすることを可能にする演算子(または関数)を探しています:
ghci> f `op` tuple
3
「スプラット」と呼ばれるのを見(<*>)
たことがありますが、他の言語のスプラットと同じものを指しているようには見えません。私はとにかくそれを試しました:
ghci> import Control.Applicative
ghci> f <*> tuple
<interactive>:1:7:
Couldn't match expected type `b0 -> b0'
with actual type `(Integer, Integer)'
In the second argument of `(<*>)', namely `tuple'
In the expression: f <*> tuple
In an equation for `it': it = f <*> tuple