Create an infinite list of alternating 1
s and 0
s, like so:
1:0:1:0:....
module Knot where
import Debug.Trace
onesAndZeroes :: Num a => [a]
onesAndZeroes =
let x = 1 : y
y = 0 : x
in x
module ExampleSpec where
-- Tests can be written using Hspec http://hspec.github.io/
-- Replace this with your own tests.
import Test.Hspec
import Knot
-- `spec` of type `Spec` must exist
spec :: Spec
spec = do
describe "Some taken values are correct" $ do
it "take some values" $ do
(take 4 onesAndZeroes) `shouldBe` ([1, 0, 1, 0])
-- the following line is optional for 8.2
main = hspec spec
Write a metafunction whose result type reverses the template parameters of a std::tuple
.
(Maybe, possibly, functional programming.)
// For convenience
template <typename, typename>
struct append;
template <typename ...Ts, typename ...Us>
struct append<std::tuple<Ts...>, std::tuple<Us...>> {
using type = std::tuple<Ts..., Us...>;
};
template <typename>
struct reverse;
template <typename T, typename ...Ts>
struct reverse<std::tuple<T, Ts...>> {
using type = typename append<
typename reverse<std::tuple<Ts...>>::type,
std::tuple<T>
>::type;
};
template <>
struct reverse<std::tuple<>> {
using type = std::tuple<>;
};
static_assert(
std::is_same_v<
reverse<std::tuple<int, short, char>>::type,
std::tuple<char, short, int>
>
);
static_assert(
std::is_same_v<
reverse<std::tuple<int&, short, char, void, int*>>::type,
std::tuple<int*, void, char, short, int&>
>
);
// Test cases are compile-time, so if we got here, it passed.
Describe(any_group_name_you_want)
{
It(should_do_something)
{
Assert::That(true);
}
};