Swift: Unreasonably slow typechecking performance w/ curried applicative functions

Originator:rix.rob
Number:rdar://19029974 Date Originated:19-Nov-2014 10:16 AM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode 6.1.1 (6A2006)
Classification:Serious Bug Reproducible:Always
 
Summary:
Trying to typecheck a simple program using currying & applicative functors is unreasonably slow.


Steps to Reproduce:
1. Compile this program (note that it does not pass typechecking):

func curry<A, B, R>(f: (A, B) -> R) -> A -> B -> R {
	return { a in { b in f(a, b) } }
}

infix operator <*> { associativity left precedence 150 }
func <*><A, B>(lhs: (A -> B)?, rhs: A?) -> B? {
	if let lhs1 = lhs {
		if let rhs1 = rhs {
			return lhs1(rhs1)
		}
	}
	return nil
}

func cons<T, U>(lhs: T, rhs: U) -> (T, U) {
	return (lhs, rhs)
}

var str1: String? = "👍"
var str2: String? = "👍"
var str3: String? = "👍"

if let f = curry(cons) <*> str1 <*> curry(cons) <*> str2 <*> str3 {
	println("\(f)")
}


Expected Results:
Responsive (interactive!) typechecking.


Actual Results:
Resonance:Desktop rob$ time ./Applicative.swift 
./Applicative.swift:25:12: error: '(T, U)' is not a subtype of 'String -> (String -> B)'
if let f = curry(cons) <*> str1 <*> curry(cons) <*> str2 <*> str3 {
           ^

real	0m29.714s
user	0m29.414s
sys	0m0.288s


Regression:
N/A


Notes:
Attached a sample.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!