简单的Haskell绑定表达式评估

时间:2015-12-09 14:00:45

标签: haskell

任何人都可以帮助我检查这是否是评估表达式的正确方法:

  [1..2] >>= \n -> ['a', 'b'] >>= \ch -> return (n, ch)
= concat (map (\n -> ['a', 'b'] >>= \ch -> return (n, ch)) [1..2])
= concat [ ['a', 'b'] >>= \ch -> return (1, ch),
           ['a', 'b'] >>= \ch -> return (2, ch) ]
= concat [ concat (map (\ch -> return (1, ch)) ['a', 'b']),
           concat (map (\ch -> return (2, ch)) ['a', 'b']) ]
= concat [ concat [return (1, 'a'), return (1, 'b')],
           concat [return (2, 'a'), return (2, 'b')] ]
= concat [ concat [ [(1, 'a')], [(1, 'b')] ],
           concat [ [(2, 'a')], [(2, 'b')] ] ]
= concat [ [ (1, 'a'), (1, 'b') ],
           [ (2, 'a'), (2, 'b') ] ]
= [ (1, 'a'), (1, 'b'), (2, 'a'), (2, 'b') ]

考虑到这是列表理解[(n, ch) | n <- [1..2], ch <- ['a', 'b']]背后的原因,我在这里做些蠢事吗?

0 个答案:

没有答案