Browse Source

guess

master
parent
commit
78818f2f53
Signed by: Yann Esposito (Yogsototh) <yann.esposito@gmail.com> GPG Key ID: 7B19A4C650D59646
5 changed files with 27 additions and 7 deletions
  1. 2
    0
      guess/guess.cabal
  2. 1
    3
      guess/package.yaml
  3. 4
    2
      guess/src-exe/Main.hs
  4. 20
    0
      guess/src/Guess.hs
  5. 0
    2
      hwp.hsfiles

+ 2
- 0
guess/guess.cabal View File

@@ -2,7 +2,7 @@
--
-- see: https://github.com/sol/hpack
--
-- hash: b0bd48edc90ce1eed0fa5dbe1b4f6f321e28b02044e8d324cfe04b67c5839142

name: guess
version: 0.1.0.0
@@ -35,6 +35,7 @@ library
base >=4.8 && <5
, protolude
exposed-modules:
Guess
Lib
other-modules:
Paths_guess

+ 1
- 3
guess/package.yaml View File

@@ -21,8 +21,6 @@ dependencies:
- protolude
library:
source-dirs: src
exposed-modules:
- Lib
executables:
guess-exe:
main: Main.hs
@@ -69,4 +67,4 @@ benchmarks:
dependencies:
- criterion >=1.1
- guess
stability: alpha (experimental)
stability: alpha (experimental)

+ 4
- 2
guess/src-exe/Main.hs View File

@@ -1,6 +1,8 @@
import Protolude

import Lib (inc)
import Guess (guess)

main :: IO ()
main = print (inc 41)
main = do
guess
putText "Bye!"

+ 20
- 0
guess/src/Guess.hs View File

@@ -0,0 +1,20 @@
module Guess
( guess
) where

import Protolude

guess :: IO ()
guess = guessBetween 0 120

guessBetween :: Integer -> Integer -> IO ()
guessBetween minAge maxAge = do
let age = (maxAge + minAge) `div` 2
if minAge == maxAge
then putText ("You are " <> show age)
else do
putText ("Are you younger than " <> show age <> "?")
answer <- getLine
case answer of
"y" -> guessBetween minAge (age - 1)
_ -> guessBetween (if age == minAge then age + 1 else age) maxAge

+ 0
- 2
hwp.hsfiles View File

@@ -22,8 +22,6 @@ dependencies:
- protolude
library:
source-dirs: src
exposed-modules:
- Lib
executables:
{{ name }}-exe:
main: Main.hs

Loading…
Cancel
Save