| 
29297
 | 
     1  | 
{-# OPTIONS_GHC -fglasgow-exts #-}
 | 
| 
 | 
     2  | 
  | 
| 
28421
 | 
     3  | 
module Example where {
 | 
| 
 | 
     4  | 
  | 
| 
32360
 | 
     5  | 
foldla :: forall a b. (a -> b -> a) -> a -> [b] -> a;
  | 
| 
28421
 | 
     6  | 
foldla f a [] = a;
  | 
| 
 | 
     7  | 
foldla f a (x : xs) = foldla f (f a x) xs;
  | 
| 
 | 
     8  | 
  | 
| 
 | 
     9  | 
rev :: forall a. [a] -> [a];
  | 
| 
 | 
    10  | 
rev xs = foldla (\ xsa x -> x : xsa) [] xs;
  | 
| 
 | 
    11  | 
  | 
| 
32360
 | 
    12  | 
list_case :: forall a b. a -> (b -> [b] -> a) -> [b] -> a;
  | 
| 
28421
 | 
    13  | 
list_case f1 f2 (a : list) = f2 a list;
  | 
| 
 | 
    14  | 
list_case f1 f2 [] = f1;
  | 
| 
 | 
    15  | 
  | 
| 
29798
 | 
    16  | 
data Queue a = AQueue [a] [a];
  | 
| 
28421
 | 
    17  | 
  | 
| 
 | 
    18  | 
empty :: forall a. Queue a;
  | 
| 
29798
 | 
    19  | 
empty = AQueue [] [];
  | 
| 
28421
 | 
    20  | 
  | 
| 
 | 
    21  | 
dequeue :: forall a. Queue a -> (Maybe a, Queue a);
  | 
| 
29798
 | 
    22  | 
dequeue (AQueue [] []) = (Nothing, AQueue [] []);
  | 
| 
 | 
    23  | 
dequeue (AQueue xs (y : ys)) = (Just y, AQueue xs ys);
  | 
| 
 | 
    24  | 
dequeue (AQueue (v : va) []) =
  | 
| 
31848
 | 
    25  | 
  let {
 | 
| 
28421
 | 
    26  | 
    (y : ys) = rev (v : va);
  | 
| 
31848
 | 
    27  | 
  } in (Just y, AQueue [] ys);
  | 
| 
28421
 | 
    28  | 
  | 
| 
 | 
    29  | 
enqueue :: forall a. a -> Queue a -> Queue a;
  | 
| 
29798
 | 
    30  | 
enqueue x (AQueue xs ys) = AQueue (x : xs) ys;
  | 
| 
28421
 | 
    31  | 
  | 
| 
 | 
    32  | 
}
  |