THIS IS THE MO St„ TIMPORATN POS T
I enjoy functional programming and cookies.
Just worked out that, as far as I can tell, the operations defined for a subtyping relation
a <: b can be directly captured by a
Lens' a b.
Namely the operations:
view : (a <: b) -> a -> b over : (a <: b) -> (b -> b) -> a -> a
Recall that a
Lens' can be defined as such:
type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t type Lens' s a = Lens s s a a
A brief subtyping example:
-- Assuming Fruit : Type Apple : Type apple : Apple -- An Apple is a Fruit rel : Apple <: Fruit -- Given an Apple we can soundly view it as a Fruit view rel : Apple -> Fruit view rel apple : Fruit -- If we can transform a Fruit, then we can trivially transform an Apple f : Fruit -> Fruit over rel : (Fruit -> Fruit) -> Apple -> Apple over rel f : Apple -> Apple over rel f apple : Apple
over are functions that work with
Quick attempt at https://www.codeeval.com/browse/156/
My approach uses
State and its associated
Applicative instance along with
traverse - just for fun.
I’m a Haskell dabbler. I’ve never written anything substantial with it - this is the first time I’ve ever actually used
traverse since learning about them.
import Data.Traversable (Traversable, traverse) import Data.Char (toUpper, toLower, isLetter) import Control.Applicative ((<$>), pure) import Control.Monad.State (State, state, evalState) -- Retrieves the next case and negates the state nextCase :: State Bool Bool nextCase = state (\upper -> (upper, not upper)) -- Apply a case to a given letter applyCase :: Char -> Bool -> Char applyCase letter upper = (if upper then toUpper else toLower) letter -- Statefully process a given character. If the character is a letter, we -- apply and switch cases. Otherwise leave it as is. processChar :: Char -> State Bool Char processChar chr = if isLetter chr then applyCase chr <$> nextCase else pure chr -- Process a traversable of characters by alternating upper and lower case -- for just the letter characters caseify :: Traversable t => t Char -> t Char caseify chrs = evalState (traverse processChar chrs) True
With the following test case:
input :: [String] input = ["To be, or not to be: that is the question.", "Whether 'tis nobler in the mind to suffer", "The slings and arrows of outrageous fortune,", "Or to take arms against a sea of troubles,", "And by opposing end them? To die: to sleep."] test :: IO () test = mapM_ (putStrLn . caseify) input
Output of running
To Be, Or NoT tO bE: tHaT iS tHe QuEsTiOn. WhEtHeR 'tIs NoBlEr In ThE mInD tO sUfFeR ThE sLiNgS aNd ArRoWs Of OuTrAgEoUs FoRtUnE, Or To TaKe ArMs AgAiNsT a SeA oF tRoUbLeS, AnD bY oPpOsInG eNd ThEm? To DiE: tO sLeEp.
For the first time ever, a paralyzed man can move his fingers and hand with his own thoughts thanks to a new device. A 23-year-old quadriplegic is the first patient to use Neurobridge, an electronic neural bypass for spinal cord injuries that reconnects the brain directly to muscles, allowing voluntary and functional control of a paralyzed limb.
Take a smooth, closed convex curve and slide a chord of constant length around it. Meanwhile consider a point on the moving chord that divides it into parts of length a and b. This point also traces out a closed curve as the chord makes a round.
Now, what is the area between the curves? I had no idea. But by Holditch’s theorem, it is simply: π a b.
Building a DBMS in Scala - Tiark Rompf
Learned this the other day in BioPsych:
The reason why flashcards are a great way to memorize concepts and terms is because when you study with them, you make your brain work hard to retrieve information from your memory.The more you do this, the better it stays in your long-term memory.
—> To remember things better, you must make yourself retrieve that information several times.
This is also the reason why simply reading over your notes a thousand times won’t help you study. Because you’re not working hard to retrieve any information, the info is not consolidated in your long-term memory and stays in your working memory (only up to 5 seconds max).
P.S. Sorry about the long absence! Last couple weeks of the quarter are crazy.
“The Deer God is a breathtaking 3d pixel art game that will challenge your religion and your platforming skills.”
Correction - 7 Days. 5k from goal.