<commit_before>{-# LANGUAGE ScopedTypeVariables #-}

import Control.Monad
-- import Data.Array
-- import Data.List hiding (union)
import Data.List.Grouping (splitEvery)

import Graphics.UI.WX hiding (Event)
-- import Graphics.UI.WXCore hiding (Event)

import Reactive.Banana
import Reactive.Banana.WX

splitInGroupsOf :: Int -> [a] -> [[a]]
splitInGroupsOf n = takeWhile ((n ==) . length)
                  . splitEvery n

main :: IO ()
main = start buttonPad

buttonPad ::  IO ()
buttonPad = do
       pad    <- frame [ text := "[1..9]" ]
       noText <- staticText pad [text := ""]
       btns   <- mapM (\n -> button pad
                             [ size := sz 40 40
                             , text := [n]])
                 ['1'..'9']
       set pad [ layout := column 5
                    [ grid 0 0
                    . map (map widget)
                    . splitInGroupsOf 3
                    $ btns
                    , widget noText ]]
       let networkDescription :: forall t. Frameworks t => Moment t ()
           networkDescription = do
               -- convert WxHaskell events to FRP events
               let eventify         :: (Commanding w) => [w] -> Moment t [Event t ()]
                   eventify widgets = forM widgets $ \x -> event0 x command

               events <- eventify btns

               let chosen :: Event t Int
                   chosen = foldl1 union
                          . zipWith (<$) [1..]
                          $ events

                   bSet   = stepper 0 chosen
               eSet   <- changes bSet
               reactimate' $ fmap print
                          <$> eSet

       network <- compile networkDescription
       actuate network
<commit_msg>Rewritten main window of `nineButtons`, to become Sudoku main frame. Written translation from panel coordinates to cartesian coordinates, used by Sudoku solver module.<commit_after>{-# LANGUAGE ScopedTypeVariables #-}

import Control.Monad
-- import Data.Array
-- import Data.List hiding (union)
import Data.List.Grouping (splitEvery)

import Graphics.UI.WX hiding (Event)
-- import Graphics.UI.WXCore hiding (Event)

import Reactive.Banana
import Reactive.Banana.WX

splitInGroupsOf :: Int -> [a] -> [[a]]
splitInGroupsOf n = takeWhile ((n ==) . length)
                  . splitEvery n

main :: IO ()
main = start buttonPad

buttonPad ::  IO ()
buttonPad = do
       pad    <- frame [ text := "Sudoku frame" ]
       noText <- staticText pad [text := ""]
       btns   <- replicateM 9
               $ mapM (\n -> button pad
                             [ size := sz 40 40
                             , text := [n]])
                 ['1'..'9']
       set pad [ layout := column 5
                           [( grid 15 15
                            . map ( map ( grid 0 0
                                        . map ( map widget )
                                        . splitInGroupsOf 3))
                            . splitInGroupsOf 3) btns
                           , widget noText]
                    ]
       let networkDescription :: forall t. Frameworks t => Moment t ()
           networkDescription = do
               -- convert WxHaskell events to FRP events
               let eventify         :: (Commanding w) => [w] -> Moment t [Event t ()]
                   eventify widgets = forM widgets $ \x -> event0 x command

               events <- eventify . concat $ btns

               let chosen :: Event t (Int, Int)
                   chosen = foldl1 union
                          . zipWith (<$) [(x,y) | x <- [1..9]
                                                , y <- [1..9]]
                          $ events

                   bSet   = stepper (-1,-1) chosen
               eSet   <- changes bSet
               reactimate' $ fmap (print . positionToCoordinates)
                          <$> eSet

       network <- compile networkDescription
       actuate network

positionToCoordinates :: (Int, Int) -> (Int, Int)
positionToCoordinates
          (glob, loc) = (x, y)
        where x       = 3*x1 + x0
              y       = 3*y1 + y0
              (y1,x1) = (glob - 1) `divMod` 3
              (y0,x0) = (loc  - 1) `divMod` 3

{'fraction_non_alphanumeric': 0.1026923993328568, 'fraction_numerical': 0.012866333095067906, 'mean_word_length': 1.2461209202782237, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3460798', 'n_tokens_mistral': 1179, 'n_tokens_neox': 1092, 'n_words': 356}