If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.
Output has to be written to STDOUT or closest alternative.
Stack Exchange network consists of 183 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack ExchangeStack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Explore Stack InternalIf (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.
Output has to be written to STDOUT or closest alternative.
If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.
Output has to be written to STDOUT or closest alternative.
If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.
Output has to be written to STDOUT or closest alternative.
{-#LANGUAGE FlexibleInstances,FunctionalDependencies,UndecidableInstances,CPP#-} #define i instance #define c class data F data T data S n data C x s c A p q r|p q->r i A F q F i A T q q c E p x y z|p x y->z i E F x y y i E T x y x c G x y b|x y->b i G x F T i G F(S y)F i G x y b=>G(S x)(S y)b c M x y z|x y->z i M x F x i M F(S y)F i M x y z=>M(S x)(S y)z c D x y b|x y->b i D x F T i(G(S y)x p,M(S y)x z,D x z q,A p q b)=>D x(S y)b c K f x y|f x->y i D m n b=>K(S n)m b c I f s n|f s->n i I f F F i(K f x b,I f s m,E b(S m)m n)=>I f(C x s)n c R n s|n->s i R F F i R n s=>R(S n)(C(S n)s) c Q m n b|m n->b i Q F F T i Q F(S y)F i Q(S x)F F i Q x y b=>Q(S x)(S y)b c P n b|n->b i(R n s,I(S n)s m,Q m(S(S F))b)=>P n b This has got to be the most beautiful code I've ever written. It's a compile-time metaprogram that determines whether a type (represented Peano-style, where F is zero and S n is n's successor) is prime.
This works in GHC 8.2.2, the version TIO currently uses. It works locally in 8.8.3 as well. I have included the language extensions in the code, all except one—the TIO example linked above has MonoLocalBinds to suppress a warning. The program works just fine without them.
If (and only if) your language is unable to accept any kind of user input, you may hardcode the input in your program.
Output has to be written to STDOUT or closest alternative.
As far as I know, metaprograms like this have no means of I/O. With FunctionalDependencies, typeclasses can act much like functions, and in this way, the typeclass P is a "function" from natural numbers to booleans (T and F—yes, the same type represents zero, false, and the empty list). I believe this to be the closest alternative to the standard streams.
The test suite I provided covers numbers from one to twenty. Try changing any T to F or vice-versa, and the program will fail to compile.
I know there are improvements that can be made, and I'll be updating this answer soonish with them.