<commit_before>-- Exercise_5_2.idr

-- Implement a guessing game fro numbers

module Main

import System
import ReadNum

||| Guessing game: Interactive dialogs to guess a given number.
||| @target the number to be guessed
||| @guesses the number of trials
guess : (target : Nat) -> (guesses : Nat) -> IO ()
guess target guesses =
  do putStr ("Guess my number " ++ "(" ++ (show guesses) ++ " trial): ")
     Just trial <- readNumber | Nothing => (putStrLn "Invalid input! Try again.." >>= \_ =>
                                          guess target guesses)
     case compare trial target of
          EQ => putStrLn "Correct!"
          LT => putStrLn "Too small, try again.." >>= \_ => guess target (S guesses)
          GT => putStrLn "Too large, try again.." >>= \_ => guess target (S guesses)


main : IO ()
main = do
  tsecs <- time
  let target = tsecs `mod` 100
  guess (cast target) 1

<commit_msg>type signature for myRepl & myReplWith<commit_after>-- Exercise_5_2.idr

-- Implement a guessing game fro numbers

module Main

import System
import ReadNum

||| Guessing game: Interactive dialogs to guess a given number.
||| @target the number to be guessed
||| @guesses the number of trials
guess : (target : Nat) -> (guesses : Nat) -> IO ()
guess target guesses =
  do putStr ("Guess my number " ++ "(" ++ (show guesses) ++ " trial): ")
     Just trial <- readNumber | Nothing => (putStrLn "Invalid input! Try again.." >>= \_ =>
                                          guess target guesses)
     case compare trial target of
          EQ => putStrLn "Correct!"
          LT => putStrLn "Too small, try again.." >>= \_ => guess target (S guesses)
          GT => putStrLn "Too large, try again.." >>= \_ => guess target (S guesses)


||| Mimic replWith function from Prelude module
myReplWith : (state : a) -> (prompt : String) -> (onInput : a -> String -> Maybe (String, a)) -> IO ()


||| Mimic repl function from Prelude module
myRepl : (prompt : String) -> (onInput : String -> String) -> IO ()


main : IO ()
main = do
  tsecs <- time
  let target = tsecs `mod` 100
  guess (cast target) 1


{'fraction_non_alphanumeric': 0.1342504743833017, 'fraction_numerical': 0.0056925996204933585, 'mean_word_length': 2.586734693877551, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 41, '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': '6328311', 'n_tokens_mistral': 679, 'n_tokens_neox': 633, 'n_words': 247}