Skip to content

Help! How to use dtfold ? #2400

Answered by christiaanb
pbreuer asked this question in Q&A
Jan 9, 2023 · 6 comments · 21 replies
Discussion options

You must be logged in to vote

Try this:

combi :: SNat n -> (Index (2^n) -> x) -> (Index (2^n) -> x) -> (Index (2^(n+1)) -> x)
combi SNat f1 f2 = \i -> if msb i == 0 then f1 i' else f2 i'   where i' = lowbits i

Pattern matching on the SNat (of type SNat n) introduces the KnownNat n constraint for anything in scope of the pattern match. As a result, you no longer need the KnownNat n constraint in the type signature of combi, since anything inside the definition of combi will now get the KnownNat n out of the SNat.

Replies: 6 comments 21 replies

Comment options

You must be logged in to vote
3 replies
@pbreuer
Comment options

@leonschoorl
Comment options

@leonschoorl
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
5 replies
@rowanG077
Comment options

@rowanG077
Comment options

@pbreuer
Comment options

@rowanG077
Comment options

@pbreuer
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by pbreuer
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
13 replies
@pbreuer
Comment options

@rowanG077
Comment options

@pbreuer
Comment options

@rowanG077
Comment options

@pbreuer
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants