-
Notifications
You must be signed in to change notification settings - Fork 642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add usleep from System to Effect.System #3749
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ module Effect.System | |
import Effects | ||
import System | ||
import Control.IOExcept | ||
import public Data.So | ||
|
||
%access public export | ||
|
||
|
@@ -14,18 +15,23 @@ data System : Effect where | |
Time : sig System Integer | ||
GetEnv : String -> sig System (Maybe String) | ||
CSystem : String -> sig System Int | ||
Usleep : (i : Int) -> | ||
{auto prf : So (i >= fromInteger 0 && Delay (i <= fromInteger 1000000))} -> | ||
sig System () | ||
|
||
implementation Handler System IO where | ||
handle () Args k = do x <- getArgs; k x () | ||
handle () Time k = do x <- time; k x () | ||
handle () (GetEnv s) k = do x <- getEnv s; k x () | ||
handle () (CSystem s) k = do x <- system s; k x () | ||
handle () (Usleep i) k = do usleep i; k () () | ||
|
||
implementation Handler System (IOExcept a) where | ||
handle () Args k = do x <- ioe_lift getArgs; k x () | ||
handle () Time k = do x <- ioe_lift time; k x () | ||
handle () (GetEnv s) k = do x <- ioe_lift $ getEnv s; k x () | ||
handle () (CSystem s) k = do x <- ioe_lift $ system s; k x () | ||
handle () (Usleep i) k = do ioe_lift $ usleep i; k () () | ||
|
||
--- The Effect and associated functions | ||
|
||
|
@@ -43,3 +49,8 @@ getEnv s = call $ GetEnv s | |
|
||
system : String -> Eff Int [SYSTEM] | ||
system s = call $ CSystem s | ||
|
||
usleep : (i : Int) -> | ||
{auto prf : So (i >= fromInteger 0 && Delay (i <= fromInteger 1000000))} -> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment regarding the use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any reason you do not use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I missed that this calls the effect, whose handler uses the system one. |
||
Eff () [SYSTEM] | ||
usleep i = call $ Usleep i |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you use
fromInteger
here explicitly? literals should be overloaded. The same withDelay
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I would in the constructor probably not use
auto
, only in the external signature used by the user.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just copied the type from
System.usleep
.fromInteger
is probably not necessary, it's shown when you type:t usleep
in REPL, but it's not present in the source file. However,auto
is used in that source file. Should I still remove it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artemohanjanyan Yeah, so I am not sure it is necessary for a constructor to have it. I would just take an argument
(inbounds : So (i >= 0 && i <= 1000000))
.