doc-src/Codegen/Thy/examples/Example.hs
author haftmann
Thu, 02 Sep 2010 16:53:23 +0200
changeset 39068 5ac590e8b320
parent 37610 1b09880d9734
child 39210 985b13c5a61d
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
29297
62e0f892e525 updated generated files;
wenzelm
parents: 28421
diff changeset
     1
{-# OPTIONS_GHC -fglasgow-exts #-}
62e0f892e525 updated generated files;
wenzelm
parents: 28421
diff changeset
     2
28421
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
     3
module Example where {
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
     4
29798
6df726203e39 proper datatype abstraction example
haftmann
parents: 29297
diff changeset
     5
data Queue a = AQueue [a] [a];
28421
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
     6
39068
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
     7
empty :: forall a. Example.Queue a;
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
     8
empty = Example.AQueue [] [];
28421
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
     9
39068
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    10
dequeue :: forall a. Example.Queue a -> (Maybe a, Example.Queue a);
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    11
dequeue (Example.AQueue [] []) = (Nothing, Example.AQueue [] []);
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    12
dequeue (Example.AQueue xs (y : ys)) = (Just y, Example.AQueue xs ys);
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    13
dequeue (Example.AQueue (v : va) []) =
31848
e5ab21d14974 updated generated document
haftmann
parents: 31544
diff changeset
    14
  let {
37610
1b09880d9734 updated generated document
haftmann
parents: 37428
diff changeset
    15
    (y : ys) = reverse (v : va);
39068
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    16
  } in (Just y, Example.AQueue [] ys);
28421
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
    17
39068
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    18
enqueue :: forall a. a -> Example.Queue a -> Example.Queue a;
5ac590e8b320 updated
haftmann
parents: 37610
diff changeset
    19
enqueue x (Example.AQueue xs ys) = Example.AQueue (x : xs) ys;
28421
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
    20
05d202350b8d reorganized examples
haftmann
parents:
diff changeset
    21
}