trizip haskell implementation】的更多相关文章

1 trizip :: [a] -> [b] -> [c] -> [(a,b,c)] 2 trizip a b c 3 | null a = [] 4 | null b = [] 5 | null c = [] 6 trizip (x:xs) (y:ys) (z:zs) = (++) [(x,y,z)] (trizip xs ys zs) daniel@daniel-mint ~/haskell $ ghci GHCi, version 7.6.3: http://www.haskell…
Finding the Longest Palindromic Substring in Linear Time Finding the Longest Palindromic Substring in Linear TimeFred AkalinNovember 28, 2007 Another interesting problem I stumbled across on reddit is finding the longest substring of a given string t…
MonadCont 类型类 class Monad m => MonadCont m where callCC :: ((a -> m b) -> m a) -> m a instance MonadCont (ContT r m) where callCC = ContT.callCC class Monad m => MonadCont m where MonadState 是个类型类,它为 ContT 等封装了CPS函数的 Monad 定义了通用接口. MonadSta…
MonadState 类型类 class Monad m => MonadState s m | m -> s where get :: m s get = state (\s -> (s, s)) put :: s -> m () put s = state (\_ -> ((), s)) state :: (s -> (a, s)) -> m a state f = do s <- get let ~(a, s') = f s put s' return…
MonadWriter 类型类 class (Monoid w, Monad m) => MonadWriter w m | m -> w where writer :: (a,w) -> m a writer ~(a, w) = do tell w return a tell :: w -> m () tell w = writer ((),w) listen :: m a -> m (a, w) pass :: m (a, w -> w) -> m a lis…
MonadReader 类型类 class Monad m => MonadReader r m | m -> r where ask :: m r ask = reader id local :: (r -> r) -> m a -> m a reader :: (r -> a) -> m a reader f = do r <- ask return (f r) instance Monad m => MonadReader r (ReaderT…
第22章 扩展示例:Web客户端编程 至此,您已经看到了如何与数据库交互,解析一些数据,以及处理错误.现在让我们更进了一步,引入Web客户端库的组合. 在本章,我们将开发一个真正的应用程序:一个播客下载软件,或播客采集软件.一个播客采集软件的想法很简单.给出一系列的URL.下载每个URL并将结果存到RSS格式的XML文件中.在这个XML文件里,我们会找到用于下载音频文件的URL. 播客采集软件通常是让用户通过往他们的配置里添加RSS URL来订阅播客.然后,用户可以定期执行更新操作.播客采集软件…
http://perugini.cps.udayton.edu/teaching/courses/Spring2015/cps352/index.html#lecturenotes Programming Languages: Chapter 1: Introduction Programming languages Some fundamental questions what is a language? a medium of communication what is a program…
参考:http://stackoverflow.com/a/9153617 http://www.haskell.org/haskellwiki/How_to_write_a_Haskell_program 1 2 3 trizip :: [a] -> [b] -> [c] -> [(a,b,c)] 4 trizip a b c 5 | null a = [] 6 | null b = [] 7 | null c = [] 8 trizip (x:xs) (y:ys) (z:zs) =…
我从问题#12 ProjectEuler作为编程练习,并比较我在C,Python,Erlang和Haskell中的实现(当然不是最优)实现.为了获得更高的执行时间,我搜索了第一个有1000个以上因子的三角形数字,而不是原始问题中所述的500个. 结果如下: <强> C: lorenzo@enzo:~/erlang$ gcc -lm -o euler12.bin euler12.c lorenzo@enzo:~/erlang$ time ./euler12.bin 842161320 real…