Programming Puzzles & Code Golf Stack Exchange is a question and answer site for programming puzzle enthusiasts and code golfers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Find an expression, at most 100 bytes long, with the longest type signature.


  • Any statically typed language with type inference is allowed
  • The type must be non-ambiguous, but otherwise may include types without defined instances. For example Num [a] and Eq [a] are allowed, even without a defined instance
  • No imports other than the minimum required to compile a program with STDIN/STDOUT
  • Infinite types are not allowed
  • If an answer has more than one expression, only one may contribute to the score. For example, although the type signature of composition is (.) :: (b -> c) -> (a -> b) -> a -> c, having a score of 20, the answer with 25 copies of (.)\n would have a score of 20, not 500
  • The expression must be, at most, 100 bytes
  • The score is the number of characters in the type signature, excluding the name of the function and any whitespace. For example, f :: (a -> b) -> a -> b would have a score of 12
  • The highest score wins!


Although other languages are allowed, the following examples are in Haskell:

Score: 112
f :: (a -> b)
 -> [[[[[[[[[[[[[[[[[[[[[[[[[a]]]]]]]]]]]]]]]]]]]]]]]]]
 -> [[[[[[[[[[[[[[[[[[[[[[[[[b]]]]]]]]]]]]]]]]]]]]]]]]]    

Score: 240
f :: (b->c)->(a->a1->a2->a3->a4->a5->a6->a7->a8->a9->a10->a11->a12->a13->a14->a15->a16->a17->a18->a19->a20->a21->a22->a23->a24->b)->a1->a2->a3->a4->a5->a6->a7->a8->a9->a10->a11->a12->a13->a14->a15->a16->a17->a18->a19->a20->a21->a22->a23->a24->c

Score: 313
f :: (Foldable t, Foldable t1, Foldable t2, Foldable t3, Foldable t4,
  Foldable t5, Foldable t6, Foldable t7, Foldable t8, Foldable t9,
  Foldable t10, Foldable t11, Foldable t12, Foldable t13,
  Foldable t14, Foldable t15) =>
 (b -> c)
 -> t (t1 (t2 (t3 (t4 (t5 (t6 (t7 (t8 (t9 (t10 (t11 (t12 (t13 (t14 (t15 (b
 -> b))))))))))))))))
 -> b
 -> c

Score: 538
    (a -> ([[c]] -> t3 [[a1 -> f b]]) -> [[c]] -> t3 [[a1 -> f b]]),
    (([[c]] -> t3 [[a1 -> f b]])
     -> t1 (t2 ([[c]] -> t3 [[a1 -> f b]]))
     -> [[c]]
     -> t3 [[a1 -> f b]]),
    (t (t1 (t2 ([[c]] -> t3 [[a1 -> f b]])))
     -> t1 (t2 ([[c]] -> t3 [[a1 -> f b]]))),
  Applicative f, Foldable t,
  Foldable ((->) (t1 (t2 ([[c]] -> t3 [[a1 -> f b]])) -> a)),
    ((->) (([[c]] -> t3 [[a1 -> f b]]) -> a -> t3 [a1 -> f b])),
  Traversable t1, Traversable t2, Traversable t3, Traversable t4,
  Traversable t5,
  Traversable ((->) (t1 (t2 ([[c]] -> t3 [[a1 -> f b]])))),
  Traversable ((->) ([[c]] -> t3 [[a1 -> f b]]))) =>
 [(t5 (t4 a1) -> f (t5 (t4 b))) -> c -> a1 -> f b]
 -> [(String, String)]
share|improve this question
Related. I did think there was an almost exact dupe, but I haven't found it. – Peter Taylor Feb 12 at 8:12
I suspect that a language with dependent typing can make a type signature of the length of any number of can compute. – xnor Feb 12 at 8:12
@xnor As type systems themselves may be turing complete (, I guess it becomes more of a busy beaver problem then. Should I edit the tags? – Michael Klein Feb 12 at 8:17

Haskell, ~2^(2^18)

f x=(x,x)

Each application of f roughly double the type signature by transforming the type signature T to (T,T). For example, the fourfold composition f.f.f.f$0 has type

Num a => ((((a, a), (a, a)), ((a, a), (a, a))), (((a, a), (a, a)), ((a, a), (a, a))))

Each line quadraples the number of applications of f, giving 4^9 = 2^18 at the end. So, the type signature has size of the order of 2^(2^18).

share|improve this answer
The classic approach, but I think the parameters can be better tuned. Specifically, I think that f x=(x,x,x) at the cost of one n. in the last line gives the optimal score for this overall structure. – Peter Taylor Feb 12 at 9:11
I don't know Haskell, so I could be off base here, but I'll point out that 4^(4^4) is less than 3^(4^5) – Sparr Feb 12 at 18:01
Pretty sure the 4th n. is going to be larger. 2^18 vs 3 * (2^16) unless I made a mistake calculating the original exponentiation: 2^(4^9) vs. 3^((4^8)*3) – Draco18s Feb 12 at 18:20

Java, score 17301488

Requires the method <T>java.util.Map<T,T>f(T t){return null;}, which has been counted towards the 100-byte limit.


The compile-time type signature of this should match this.

share|improve this answer

C++11, noncompeting

I barely can't get this under 100 bytes, but it's so close I figured I might post it anyway, in the hopes that someone spots an optimization.

This is the prologue, costing 93 bytes:

#define t(a,b,c)template<a>union A b{using T=c(*)(c);};
t(int N,,typename A<N-1>::T)t(,<0>,A)

And the expression, 9 bytes:


To illustrate:

Expr       Type
A<0>::T()  A<0> (*)(A<0>)
A<1>::T()  A<0> (*(*)(A<0> (*)(A<0>)))(A<0>)
A<2>::T()  A<0> (*(*(*)(A<0> (*(*)(A<0> (*)(A<0>)))(A<0>)))(A<0> (*)(A<0>)))(A<0>)

Roughly doubling every time the number increases.

share|improve this answer

C#, 363



Type signature:


Try it online!

share|improve this answer

C, 979

#define a int,int,int
#define b a,a,a,a
#define c b,b,b
#define d c,c,c
#define e d,d,d

f has the signature:

share|improve this answer
979 33554438 58640620148060 this looks like some ridiculous OEIS entry. possibly the largest changes in magnitude I've ever seen in a PPCG entry being refined. – Sparr Feb 12 at 17:56
@Sparr you ain't seen nuthin' yet – cat Mar 15 at 3:45

Haskell, 782



Type signature:

:: (Num [[[[[[[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[[c]]]]]]]]]]]]]]], Num [[[[[[[[[[[[[[c]]]]]]]]]]]]]], Num [[[[[[[[[[[[[c]]]]]]]]]]]]], Num [[[[[[[[[[[[c]]]]]]]]]]]], Num [[[[[[[[[[[c]]]]]]]]]]], Num [[[[[[[[[[c]]]]]]]]]], Num [[[[[[[[[c]]]]]]]]], Num [[[[[[[[c]]]]]]]], Num [[[[[[[c]]]]]]], Num [[[[[[c]]]]]], Num [[[[[c]]]]], Num [[[[c]]]], Num [[[c]]], Num [[c]], Num [c], Num c) => [[[[[[[[[[[[[[[[[[[[[[[[[c]]]]]]]]]]]]]]]]]]]]]]]]] -> c
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.