From Small Dolphin, 6 Months ago, written in Haskell.
Embed
  1. -- related to https://stackoverflow.com/questions/66370965/polymorphic-input-function-with-multiple-argument-types/66371082?noredirect=1#comment117368103_66371082
  2.  
  3. {-# LANGUAGE RankNTypes #-}
  4.  
  5. main = putStrLn (foo id)
  6.  
  7. foo :: (forall a. Show a => a -> String) -> String
  8. foo fn =
  9.     let
  10.         val1 = fn "hey"
  11.         val2 = fn 42
  12.     in
  13.         val1 <> val2
  14.  
  15.  
  16. -- main.hs:3:22: error:
  17. --    * Couldn't match type `a' with `String'
  18. --      `a' is a rigid type variable bound by
  19. --        a type expected by the context:
  20. --          forall a. Show a => a -> String
  21. --        at main.hs:3:18-23
  22. --      Expected type: a -> String
  23. --        Actual type: String -> String
  24. --    * In the first argument of `foo', namely `id'
  25. --      In the first argument of `putStrLn', namely `(foo id)'
  26. --      In the expression: putStrLn (foo id)
  27. --  |
  28. --3 | main = putStrLn (foo id)
  29. --  |                      ^^
  30. --compiler exit status 1