Skip to content

Instantly share code, notes, and snippets.

@sordina
Last active January 26, 2017 11:23
Show Gist options
  • Select an option

  • Save sordina/2f983cbc079fcd0171ac42e06d860c7d to your computer and use it in GitHub Desktop.

Select an option

Save sordina/2f983cbc079fcd0171ac42e06d860c7d to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TemplateHaskell #-}
import Control.Lens
import Control.Lens.Operators
import Data.List
import Control.Monad
import Control.Monad.State
vec1 = [1 .. 3]
vec2 = [11 .. 13]
myZipWith op [] [] = []
myZipWith op _ [] = error "dimension mismatch"
myZipWith op [] _ = error "dimension mismatch"
myZipWith op (hL1:tL1) (hL2:tL2) =
op hL1 hL2 : myZipWith op tL1 tL2
main = do
print vec1
print vec2
print (zipWith (+) vec1 vec2)
data Foo = Foo { _x :: Int
, _y :: Double
} deriving (Show)
makeLenses ''Foo
myData = Foo 1 2
foo = myData &~ loop
where
loop = forM_ [2..8] $ \t -> do
x += 5
x += 6
q <- use x
x += 2
x += t
y -= 55
primes :: [Integer]
primes = 2 : 3 : 5 : filter (isPrime) [7..]
isPrime = not . isNotPrime
isNotPrime x = any (x `isDivisibleBy`) (asManyAsWeNeed x primes)
asManyAsWeNeed x l = takeWhile (<= lbsqr x) l
lbsqr x = floor (sqrt (fromIntegral x))
isDivisibleBy a b = 0 == a `mod` b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment