File: test2.hs

package info (click to toggle)
haskell-memoize 1.1.2-3
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 108 kB
  • sloc: haskell: 401; makefile: 2
file content (17 lines) | stat: -rw-r--r-- 467 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{-# language TemplateHaskell #-}

import Data.Function.Memoize
import Data.Function ( fix )

data List a = Nil | Cons a (List a)

$(deriveMemoizable ''List)

main = print $
  let lcs = memoFix2 -- exponential time if you put   fix   here
          $ \ f -> \ a b -> case (a,b) of
            (Cons x a', Cons y b') ->
               maximum [ if x == y then 1 + f a' b'  else 0, f a b', f a' b ]
            _ -> 0
      a = iterate (Cons ()) Nil !! 20
  in  lcs a a