Haskell: makeNtuple function?

Is there a function or functions in Haskell that takes n arguments and returns an n-tuple? For instance:

make3tuple:: a -> a -> a -> (a,a,a)
make3tuple a b c = (a,b,c)

i.e.: as a comma, but for more than two arguments. Obviously, make3tuple does the job, but I feel there must be a built-in way to do this, and I have not found it, or have missed some way to use some other ubiquitous function.

FWIW, this occurs when using liftM3 (or higher). For instance:

type RandomState a = State StdGen a
[...]
getTwoRandoms = liftM2 (,) getRandom getRandom
get3Randoms = liftM3 make3tuple getRandom getRandom getRandom

Thank!

+5
source share
2 answers

Yes.

(,,) :: a -> b -> c -> (a, b, c)
(,,,) :: a -> b -> c -> d -> (a, b, c, d)

and etc.

So you can write liftM3 (,,) getRandom getRandom getRandom

Haskell compilers provide such functions up to a certain size (I think the guarantee is 15 tuples)

+12
source

, makeNtuple :: Int -> a -> a -> ... -> (a,a,...), , . , , "dependint-typed" Vector s

data Nat = Ze | Su Nat

data Vec :: * -> Nat -> * where
  Nil  :: Vec a Ze
  Cons :: a -> Vec a n -> Vec a (Su n)
+1

All Articles