on master help sign in
Idris-dev/samples/effects/Exception.idr
21 lines 521 B history raw
1module Main
3import Effects
4import Effect.Exception
5import Effect.StdIO
6import Control.IOExcept
8data MyErr = NotANumber | OutOfRange
10implementation Show MyErr where
11 show NotANumber = "Not a number"
12 show OutOfRange = "Out of range"
14parseNumber : Int -> String -> { [EXCEPTION MyErr] } Eff Int
15parseNumber num str
16 = if all isDigit (unpack str)
17 then let x = cast str in
18 if (x >=0 && x <= num)
19 then pure x
20 else raise OutOfRange
21 else raise NotANumber