Created
July 8, 2015 16:38
-
-
Save soegaard/cdc8cfa6a57f6ce3881d to your computer and use it in GitHub Desktop.
Does this construct have a name?
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
> (define (make-map+fold f) | |
; f : α β -> (values α β) | |
; map f over xs while threading the seconding value | |
(define (f* xs ρ) | |
(match xs | |
['() (values '() ρ)] | |
[(cons x xs) (letv ((x ρ) (f x ρ)) | |
(letv ((xs ρ) (f* xs ρ)) | |
(values (cons x xs) ρ)))])) | |
f*) | |
> (define sqr+count (make-map+fold (λ (x n) (values (sqr x) (add1 n))))) | |
> (sqr+count '(3 7 2) 0) | |
'(9 49 4) | |
3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Forgot the definition of
letv