Jason (jcreed) wrote,

Among much other hacking today, I wrote this code:
       (* val tp_reduce : tp * knd * spine -> tp
           tp_reduce (a, k, sp) computes the result
           of reducing (.\ .\ ... .\ a) . sp
           assuming (.\ .\ ... .\ a) : k
           (where the number of lambdas is the number
            of pis found in k) 

	and tp_reduce (a, k, sp) =
		fun subst_tpfn s (tpfnLam a) = tpfnLam(subst_tpfn (OneDotShift s) a)
		  | subst_tpfn s (tpfnType a) = tpfnType(subst_tp s a)
		fun tp_reduce'(tpfnLam(a), KPi(_,b,k), h::sp) = 
			val s = TermDot(termof h, b, Id)
			val a' = subst_tpfn s a
			val k' = subst_knd s k
			tp_reduce' (a', k', sp)
		  | tp_reduce' (tpfnType a, Type, []) = a
		  | tp_reduce' _ = raise Syntax "simplified-kind mismatch in type reduction" 
		fun wrap (a, KPi(_,b,k)) = tpfnLam (wrap(a,k))
		  | wrap (a, Type) = tpfnType a
		val aw = wrap (a, k)
		tp_reduce' (aw, k, sp)
to fill a gaping functionality/correctness hole in my typechecker (god damn defined type families with more than one argument!) and it magically typechecked and compiled and passed all tests the first time. That hardly ever happens to me anymore. Very satisfying.
Tags: work

  • (no subject)

    K got back tonight, pretty late in subjective time (3-4am or so, coming from europe) but all in one piece. None of her houseplants, which were…

  • (no subject)

    K is off tonight to Old Country for a couple weeks, to fulfill family-seeing obligations. Sad! Thankfully we still have internet and skype and…

  • (no subject)

    Finally home. This time instead of mysteriously attracting screaming babies I mysteriously attracted full grown adults biting their nails or maybe…

  • Post a new comment


    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded