Last active
August 29, 2015 13:56
-
-
Save mschauer/9162759 to your computer and use it in GitHub Desktop.
Hangs if call to consr gets uncommented
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract FingerTree{T} | |
immutable Node23{T} | |
child::NTuple{Any, T} | |
end | |
Node23{T}(a::T...) = Node23{T}(a) | |
immutable DeepFT{T} <: FingerTree{T} | |
left::NTuple{Any, T} | |
succ::Union(FingerTree{Node23{T}},(),Node23{T}) | |
right::NTuple{Any, T} | |
end | |
DeepFT{T}(l::NTuple{Any,T}, s, r::NTuple{Any,T}) = DeepFT{T}(l, s, r) | |
consr(f::(), a) = tuple(a) | |
consr{T}(f::NTuple{1,T}, a) = DeepFT(f, (), (a,)) | |
function consr2(ft::DeepFT, a) | |
if length(ft.right) < 4 | |
DeepFT(ft.left, ft.succ, tuple(ft.right..., a)) | |
else | |
end | |
end | |
consr2(ft,a) = consr(ft,a) | |
function consr(ft::DeepFT, a) | |
if length(ft.right) < 4 | |
DeepFT(ft.left, ft.succ, tuple(ft.right..., a)) | |
else | |
if nevermindwhatishere | |
f = (Node23(ft.right[1:3]...)) | |
# The following breaks | |
DeepFT(ft.left, consr(ft.succ, f)..., tuple(a, ft.right[4])) | |
# The following works until ERROR: nevermindwhatishere not defined | |
# DeepFT(ft.left, consr2(ft.succ, f)..., tuple(a, ft.right[4])) | |
end | |
end | |
end | |
# Illustration: Construct a tree and deconstruct it | |
ft = () | |
for i in 'A':'G' | |
ft = consr(ft,i) | |
println(ft) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment