Does Haskell have a splat operator like Python and Ruby?

前端 未结 3 1522
忘了有多久
忘了有多久 2021-01-01 19:23

In Python and Ruby (and others as well, I\'m sure). you can prefix an enumerable with * (\"splat\") to use it as an argument list. For instance, in Python:

相关标签:
3条回答
  • 2021-01-01 20:08

    The uncurry function turns a function on two arguments into a function on a tuple. Lists would not work in general because of their requirement for homogeneity.

    0 讨论(0)
  • 2021-01-01 20:18

    Yes, you can apply functions to tuples, using the tuple package. Check out, in particular, the uncurryN function, which handles up to 32-tuples:

    Prelude Data.Tuple.Curry> (+) `uncurryN` (1, 2)
    3
    
    0 讨论(0)
  • 2021-01-01 20:27

    No, Haskell's type system doesn't like that. Check this similar question for more details:

    How do I define Lisp’s apply in Haskell?

    BTW, the splat operator you talk about is also known as the apply function, commonly found on dynamical functional languages (like LISP and Javascript).

    0 讨论(0)
提交回复
热议问题