github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

osfameron / misc-opensource

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 3
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: bf54cd6

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

miscellaneous opensource stuf — Read more

  cancel

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

renamed zipGrid to mkGrid 
osfameron (author)
Mon Mar 09 17:50:25 -0700 2009
commit  bf54cd635d44d506a3166ef7d482f1b152a860fc
tree    54ad446118f48d995f4e484f62fbf508abb648e0
parent  6e4bcea882a9c2b720545b842ff257254ea8d524
misc-opensource / scratch / haskell / grid.hs scratch/haskell/grid.hs
100644 30 lines (23 sloc) 0.623 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
-- we want to fold something like this
g = [
    [ 1, 2, 3 ],
    [ 4, 5, 6 ],
    [ 7, 8, 9 ]
    ]
 
-- into a Cell { value=1, right=(the Cell with value 2), down=(the cell with value 4) }
 
data Cell a = Cell {
    value :: a,
    down :: Cell a,
    right :: Cell a
    }
    | Nil
    deriving Show
 
right' :: Cell a -> Cell a
right' c@(Cell {}) = right c
right' Nil = Nil
 
mkRow :: [a] -> Cell a -> Cell a
mkRow xs c = foldr mkCell Nil valAndDown
    where valAndDown = zip xs (iterate right' c)
          mkCell (v,d) r = Cell { value=v, down=d, right=r }
 
mkGrid :: [[a]] -> Cell a
mkGrid = foldr mkRow Nil
 
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server