christopherschwaab.wordpress.com
August | 2012 | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/08
Monthly Archives: August 2012. A-99 Lists 5 (*) Reverse a list. Reversing a list in a language like Haskell is fairly simple with plenty of solutions. The recursive algorithm we’ll use accumulates the result in a second list as the first is being traversed. Reverse : [a] - [a] reverse xs = reverse' xs [] where reverse' (x : xs) rxs = reverse' xs (x : rxs) reverse' [] rxs = rxs. However, using our Vector. The length of the output should be a function of the two inputs and. Forall;{n}{A : Set. Xs (x ∷.
christopherschwaab.wordpress.com
A-99 Lists 2 (*) Find the last but one element of a list | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/07/08/a-99-lists-2
A-99 Lists 2 (*) Find the last but one element of a list. Very similar to the first lists problem but here we need to protect against lists under length 2. Also note the use of infixr. Marking the list constructor ∷. As a right associative infix operator with precedence 5 (higher precedence binding more tightly). 8469; suc; zero) data. N : ℕ. Forall;{n} → A → Vector. A n → Vector. Forall;{A}{n} → Vector. N) → A last-but-one. This entry was posted in Programming. July 8, 2012. Leave a Reply Cancel reply.
christopherschwaab.wordpress.com
A-99 Lists 5 (*) Reverse a list | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/08/29/a-99-lists-5
A-99 Lists 5 (*) Reverse a list. Reversing a list in a language like Haskell is fairly simple with plenty of solutions. The recursive algorithm we’ll use accumulates the result in a second list as the first is being traversed. Reverse : [a] - [a] reverse xs = reverse' xs [] where reverse' (x : xs) rxs = reverse' xs (x : rxs) reverse' [] rxs = rxs. However, using our Vector. The length of the output should be a function of the two inputs and. Forall;{n}{A : Set. A n → Vec. Problem 1: n 0! A n → Vec. And t...
christopherschwaab.wordpress.com
September | 2012 | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/09
Monthly Archives: September 2012. Generating Switch Statements in C. If you prefer to skip the english you can find a copy of the source in this post here. The first thing to ask is what a “switch call” will look like. If we were designing a simple interpreter, we might switch on the operation as in the following. This is pretty suggestive of what a switch. With such a function should look something like this. Return switch operation table : run(operation, printResult, x, y);. And its static function run.
christopherschwaab.wordpress.com
A-99 Lists 1 (*) Find the last element of a list | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/07/08/a-99-lists-1
A-99 Lists 1 (*) Find the last element of a list. The list problems I’d chosen to solve using a type with known length (often referred to as a vector). The implementation is straightforward enough, the one interesting addition is the type of the first argument to last: Vector A (suc n). Which protects the call against empty lists. 8469; suc; zero) data. N : ℕ. Forall;{n} → A → Vector. A n → Vector. Forall;{A}{n} → Vector. N) → A last. X ∷ []. This entry was posted in Programming. July 8, 2012.
christopherschwaab.wordpress.com
Christopher Schwaab | Page 2
https://christopherschwaab.wordpress.com/page/2
Dumping the GoSMS Backup File. Yesterday I needed to dump a bunch of backed up text messages into a CSV and before updating my android to ice cream sandwich I had used GoSMS. I’m not sure what I had expected, but upon digging them out today I discovered they’re some native binary format. It’s about as simple as possible but I figured I may save someone in a similar position 20 minutes. Number of entries : 32 bits. Data : 32 bits. Data field 1 : Field. Message id : Field. Phone number : Field. June 5, 2012.
christopherschwaab.wordpress.com
A-99 Lists 3 (*) Find the K’th element of a list | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/08/29/a-99-lists-3
A-99 Lists 3 (*) Find the K’th element of a list. Given that inspecting an arbitrary index in a list can result in a runtime failure (what if we request index 12 of a length 2 list) we have two options. Return a datatype with an error code such as Maybe or -⊎-, or. Restrict the index by the size of the list. We choose the second option because it’s not traditionally simple or even possible in many languages. The type used to express this is Fin. The family of finite sets. As an example the type Fin 4.
christopherschwaab.wordpress.com
A-99 Lists 4 (*) Find the number of elements of a list | Christopher Schwaab
https://christopherschwaab.wordpress.com/2012/08/29/a-99-lists-4
A-99 Lists 4 (*) Find the number of elements of a list. Given that we track the number of elements in our list this problem is trivial. 8469; suc; zero) data. N : ℕ. Forall;{n} → A → Vector. A n → Vector. Forall;{n}{A : Set. A n → ℕ. This entry was posted in Programming. August 29, 2012. A-99 Lists 3 (*) Find the K’th element of a list. A-99 Lists 5 (*) Reverse a list →. One thought on “ A-99 Lists 4 (*) Find the number of elements of a list. August 30, 2012 at 5:46 pm. Leave a Reply Cancel reply.
christopherschwaab.wordpress.com
christopherschwaab | Christopher Schwaab
https://christopherschwaab.wordpress.com/author/christopherschwaab
Generating Switch Statements in C. If you prefer to skip the english you can find a copy of the source in this post here. The first thing to ask is what a “switch call” will look like. If we were designing a simple interpreter, we might switch on the operation as in the following. This is pretty suggestive of what a switch. With such a function should look something like this. Return switch operation table : run(operation, printResult, x, y);. Here the template argument int. And its static function run.