Guest User

Untitled

a guest
Jan 20th, 2019
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import Foundation
  2.  
  3.  
  4. // Given what seems to be a pretty standard definition of `curry`…
  5. public func curry<T, U, Z>(_ ƒ: @escaping (T, U) -> Z) -> (T) -> (U) -> Z {
  6. return { a in
  7. return { b in
  8. ƒ(a, b)
  9. }
  10. }
  11. }
  12.  
  13.  
  14. // Currying non-function arguments works fine.
  15. func lowerOrder(_ x: String, _ y: String) { }
  16. curry(lowerOrder) is (String) -> (String) -> Void
  17. //> true
  18.  
  19.  
  20. // But currying a higher-order function leaves us with some unknowable, unmatchable type!
  21. func higherOrder(_ x: String, _ y: (String) -> Int) { }
  22. curry(higherOrder) is (String) -> ((String) -> Int) -> Void
  23. //> false?!?!
  24.  
  25.  
  26. // Even though it looks like the type ought to be correct.
  27. print(type(of: curry(higherOrder)))
  28. //> (String) -> ((String) -> Int) -> ()
  29.  
  30.  
  31. // It only seems to be a problem when function types are in the params. Returning a function works fine.
  32. func maker(_ x: String, _ y: String) -> (String)->Int { return { _ in 42 }}
  33. curry(maker) is (String) -> (String) -> (String)->Int
  34. //> true
  35.  
  36.  
  37. // And just to be sure it's not a problem with any signature with this shape, this works fine.
  38. func staticDef(_ x: String) -> ((String) -> Int) -> Void { return { _ in 42 }}
  39. staticDef is (String) -> ((String) -> Int) -> Void
  40. //> true
Add Comment
Please, Sign In to add comment