title: The function that shall have no name
body: <p>The following code at <a href="http://ideone.com/q7fWij" rel="nofollow">http://ideone.com/q7fWij</a> compiles successfully, but when I attempt to even name the function:</p>
  
  <pre><code>(\fn (D x) -&gt; f fn x)
  </code></pre>
  
  <p>by say:</p>
  
  <pre><code>h = (\fn (D x) -&gt; f fn x)
  </code></pre>
  
  <p>I get a compile error:</p>
  
  <pre><code>SO-30447787.hs:51:19:
      Couldn't match expected type `t1' with actual type `String'
        `t1' is untouchable
          inside the constraints (Constraints t2 a)
          bound by a pattern with constructor
                     D :: forall t a. (Constraints t a) =&gt; a -&gt; D t,
                   in a lambda abstraction
          at SO-30447787.hs:51:11-13
        `t1' is a rigid type variable bound by
             the inferred type of h :: t -&gt; D t2 -&gt; t1
             at SO-30447787.hs:51:1
      Relevant bindings include
        h :: t -&gt; D t2 -&gt; t1
          (bound at SO-30447787.hs:51:1)
      In the expression: f fn x
      In the expression: (\ fn (D x) -&gt; f fn x)
  </code></pre>
  
  <p>Is there a way to name this poor function, or is it forever destined for a life of anonymity?</p>
  
  <p>(By the way, what I'm playing around with is a class that searches up a tree for a function to call). </p>
  
  <pre><code>{-# LANGUAGE TypeFamilies #-}
  {-# LANGUAGE FlexibleInstances #-}
  {-# LANGUAGE FlexibleContexts #-}
  {-# LANGUAGE UndecidableInstances #-}
  {-# LANGUAGE OverlappingInstances #-}
  {-# LANGUAGE ScopedTypeVariables #-}
  {-# LANGUAGE ExistentialQuantification #-}
  {-# LANGUAGE MultiParamTypeClasses #-}
  {-# LANGUAGE ConstraintKinds #-}
  {-# LANGUAGE NoMonomorphismRestriction #-}
  
  import GHC.Exts (Constraint)
  
  type family Parent a
  
  class C a b where
    f :: b -&gt; a -&gt; String
  
  instance (C (Parent a) b) =&gt; C a b where
    f _ _ = f (undefined :: b) (undefined :: Parent a) 
  
  data A1 = A1
  data A2 = A2
  data A3 = A3
  data A4 = A4
  
  type instance Parent A2 = A1
  type instance Parent A3 = A2
  type instance Parent A4 = A3
  
  data F1 = F1
  data F3 = F3
  
  instance C A1 F1 where
    f _ _ = "F1"
  
  instance C A3 F3 where
    f _ _ = "F3"
  
  type family Constraints t a :: Constraint
  
  data D t = forall a. (Constraints t a) =&gt; D a
  
  type instance Constraints A1 a = (C a F1)
  type instance Constraints A2 a = (C a F1, C a F3)
  type instance Constraints A3 a = (C a F1, C a F3)
  type instance Constraints A4 a = (C a F1, C a F3)
  
  main = 
    do
  --    let h = (\fn (D x) -&gt; f fn x)
      putStrLn (f F1 A1)
      putStrLn (f F1 A2)
      putStrLn (f F1 A3)
      putStrLn (f F1 A4)
      putStrLn (f F3 A3)
      putStrLn (f F3 A4)
      putStrLn $ (\fn (D x) -&gt; f fn x) F1 ((D A1) :: D A1)
      putStrLn $ (\fn (D x) -&gt; f fn x) F1 ((D A2) :: D A1)
      putStrLn $ (\fn (D x) -&gt; f fn x) F3 ((D A3) :: D A2)
  </code></pre>