I need to find an expression for a Haskell function. The function: test :: (c,b,c) -> (b,c,b)
My code of course does not work, because there are "Conflicting definitions for ‘c’".
test (c,b,c) = (b, c, b)
I need to find an expression for a Haskell function. The function: test :: (c,b,c) -> (b,c,b)
My code of course does not work, because there are "Conflicting definitions for ‘c’".
test (c,b,c) = (b, c, b)
As mentioned in the comments, if you want
test :: forall b c. (c, b, c) -> (b, c, b)
(forall
added for emphasis)
Then you can't actually do anything with the values in the tuple, since you know nothing about their respective types. So the only two (non-bottom) possible implementations of this function are
test (c, b, _) = (b, c, b)
-- or
test (_, b, c) = (b, c, b)
The first and third elements of the result tuple can only possibly be b
, as that's the only value you have of the appropriate type. The second value can be either the first or third original value.
Of course, if you allow bottom, then there are a ton of nonsense functions you can write.
test (a, b, c) = test (c, b, a)
test _ = undefined
test _ = error "Yup, this is definitely a tuple"
test (_, b, c) = (b, c, undefined)
None of these are terribly meaningful, but they will typecheck. For all practical purposes though, only the two non-bottom examples are interesting.