<commit_before>{-# LANGUAGE PackageImports, ForeignFunctionInterface, Rank2Types, ExistentialQuantification, 
             ScopedTypeVariables, FlexibleContexts #-}

module Main where

import Coroutine

import Type
import UI 
import InitDevice

import Graphics.UI.Gtk

import "mtl" Control.Monad.State

import "mtl" Control.Monad.Trans

import Data.IORef


{-newtype T = forall a. C a

newtype CoroutineIORef = forall i. forall o. forall m. forall a. CoroutineIORef { 
  runCoroutineIORef :: IORef (i -> CoroutineT i o m a)
  } 
-}


data AllCont = forall o a. (Show o)  => AllCont { runcont :: (String -> CoroutineT String o IO a) }



coroutineHandler :: IORef AllCont -> EventM a ()  
coroutineHandler contref = do 
  cont <- liftIO $ readIORef contref
  
case cont of 
    AllCont fun -> do 
      r <- liftIO $ run $ fun "test"
      case r of 
        Result a -> do 
          let newone = \_ -> CoroutineT $ (return r)  -- (Result a :: Result String o IO b)
          liftIO $ writeIORef contref (AllCont newone)
          return ()
        Yield o ncont -> do 
          liftIO $ putStrLn $ show o
          liftIO $ writeIORef contref (AllCont ncont)  
          return ()
  
  where run exp = runCoroutineT exp 



data T = forall o. (Show o) => MkT o


f :: T -> String
f (MkT o) = show o

reportPoint msg = do (x,y) <- eventCoordinates 
                     liftIO $ putStrLn $ msg ++ (show (x,y)) 
                  



myPenButtonClicked pentyperef   = do liftIO $ modifyIORef pentyperef (const Pen) 
                                     liftIO $ putStrLn "pen button clicked" 

myEraseButtonClicked pentyperef = do liftIO $ modifyIORef pentyperef (const Erase)
                                     liftIO $ putStrLn "erase button clicked"

showMode pentype = 
  case pentype of 
    Pen   -> liftIO $ putStrLn "in Pen mode" 
    Erase -> liftIO $ putStrLn "in Erase mode"

myButtonPressed statusref pentyperef = do 
  status  <- liftIO $ readIORef statusref 
  pentype <- liftIO $ readIORef pentyperef
  
  showMode pentype
                
  case status of   
    StandBy    -> do reportPoint "press:standby" 
                     liftIO $ modifyIORef statusref (const Drawing) 
    Drawing    -> reportPoint "press:drawing"
 


myMouseMoved statusref pentyperef = do 
  status <- liftIO $ readIORef statusref 
  pentype <- liftIO $ readIORef pentyperef
  
  showMode pentype
  
  case status of   
    StandBy    -> reportPoint "move:standby" 
    Drawing -> reportPoint "move:drawing"

myButtonReleased statusref pentyperef = do 
  status <- liftIO $ readIORef statusref
  pentype <- liftIO $ readIORef pentyperef
  
  showMode pentype

  case status of 
    StandBy    -> reportPoint "release:standby"
    Drawing -> do reportPoint "release:drawing"
                  liftIO $ modifyIORef statusref (const StandBy)
               
              

testCoroutine :: CoroutineT String String IO ()
testCoroutine = do 
  yield "haha" 
  yield "babo"
  yield "what are you doing"
  return ()<commit_msg>compile error removed<commit_after>{-# LANGUAGE PackageImports, ForeignFunctionInterface, Rank2Types, ExistentialQuantification, 
             ScopedTypeVariables, FlexibleContexts #-}

module Main where

import Coroutine

import Type
import UI 
import InitDevice

import Graphics.UI.Gtk

import "mtl" Control.Monad.State

import "mtl" Control.Monad.Trans

import Data.IORef


{-newtype T = forall a. C a

newtype CoroutineIORef = forall i. forall o. forall m. forall a. CoroutineIORef { 
  runCoroutineIORef :: IORef (i -> CoroutineT i o m a)
  } 
-}


data AllCont = forall o a. (Show o)  => AllCont { runcont :: (String -> CoroutineT String o IO a) }



coroutineHandler :: IORef AllCont -> EventM a ()  
coroutineHandler contref = do 
  cont <- liftIO $ readIORef contref
  
  case cont of 
    AllCont fun -> do 
      r <- liftIO $ run $ fun "test"
      case r of 
        Result a -> do 
          let newone = \_ -> CoroutineT $ (return r)  -- (Result a :: Result String o IO b)
          liftIO $ writeIORef contref (AllCont newone)
          return ()
        Yield o ncont -> do 
          liftIO $ putStrLn $ show o
          liftIO $ writeIORef contref (AllCont ncont)  
          return ()
  
  where run exp = runCoroutineT exp 



data T = forall o. (Show o) => MkT o


f :: T -> String
f (MkT o) = show o

reportPoint msg = do (x,y) <- eventCoordinates 
                     liftIO $ putStrLn $ msg ++ (show (x,y)) 
                  



myPenButtonClicked pentyperef   = do liftIO $ modifyIORef pentyperef (const Pen) 
                                     liftIO $ putStrLn "pen button clicked" 

myEraseButtonClicked pentyperef = do liftIO $ modifyIORef pentyperef (const Erase)
                                     liftIO $ putStrLn "erase button clicked"

showMode pentype = 
  case pentype of 
    Pen   -> liftIO $ putStrLn "in Pen mode" 
    Erase -> liftIO $ putStrLn "in Erase mode"

myButtonPressed statusref pentyperef = do 
  status  <- liftIO $ readIORef statusref 
  pentype <- liftIO $ readIORef pentyperef
  
  showMode pentype
                
  case status of   
    StandBy    -> do reportPoint "press:standby" 
                     liftIO $ modifyIORef statusref (const Drawing) 
    Drawing    -> reportPoint "press:drawing"
 


myMouseMoved statusref pentyperef = do 
  status <- liftIO $ readIORef statusref 
  pentype <- liftIO $ readIORef pentyperef
  
  showMode pentype
  
  case status of   
    StandBy    -> reportPoint "move:standby" 
    Drawing -> reportPoint "move:drawing"

myButtonReleased statusref pentyperef = do 
  status <- liftIO $ readIORef statusref
  pentype <- liftIO $ readIORef pentyperef
  
  showMode pentype

  case status of 
    StandBy    -> reportPoint "release:standby"
    Drawing -> do reportPoint "release:drawing"
                  liftIO $ modifyIORef statusref (const StandBy)
               
              

testCoroutine :: CoroutineT String String IO ()
testCoroutine = do 
  i <- yield "haha" 
  liftIO $ putStrLn i
  yield "babo"
  yield "what are you doing"
  return ()
{'fraction_non_alphanumeric': 0.07590976453153302, 'fraction_numerical': 0.00032932652725177014, 'mean_word_length': 2.2620837808807734, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1639210', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1891, 'n_words': 610}