File: Heap.hs

package info (click to toggle)
haskell-qio 1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 96 kB
  • ctags: 1
  • sloc: haskell: 815; makefile: 3
file content (27 lines) | stat: -rw-r--r-- 612 bytes parent folder | download
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
{-# OPTIONS_GHC -fglasgow-exts #-}

module QIO.Heap where

import qualified Data.Map as Map
import Data.Maybe as Maybe
import QIO.QioSyn

class Eq h => Heap h where
      initial :: h
      update :: h -> Qbit -> Bool -> h
      (?) :: h -> Qbit -> Maybe Bool
      forget :: h -> Qbit -> h
      hswap :: h -> Qbit -> Qbit -> h
      hswap h x y = update (update h y (fromJust (h ? x))) x (fromJust (h ? y)) 
type HeapMap = Map.Map Qbit Bool

instance Heap HeapMap where
       initial = Map.empty
       update h q b = Map.insert q b h
       h ? q = Map.lookup q h
       forget h q = Map.delete q h