Idris2-boot/tests/idris2/real001/TestProto.idr
Edwin Brady 413d09dad8 Unification tweak for getting lambda types
We've been generalising inferred function types to have multiplicity
RigW but sometimes (especially on lambdas) we need to infer the precise
type, so make a distinction.
This is pretty ugly, really. It would be better to be able to postpone
the choice until we know more, but it's not obvious to me how to achieve
that with the way unification is currently set up. The present way at
least works fine with code that doesn't use linearity, which is the
right default I think!
2020-02-09 17:05:22 +00:00

45 lines
1.1 KiB
Idris

module Main
import Channel
import Linear
import System
TestProto : Protocol ()
TestProto
= do b <- Request Bool
if b
then do Respond Char; Done
else do Respond String; Done
testClient : (1 chan : Client TestProto) -> Any IO ()
testClient chan
= do lift $ putStrLn "Starting client"
lift $ sleep 1
lift $ putStrLn "Sending value"
chan <- send chan False
lift $ putStrLn "Sent"
c @@ chan <- recv chan
lift $ putStrLn ("Result: " ++ c)
close chan
testServer : (1 chan : Server TestProto) -> Any IO ()
testServer chan
= do lift $ putStrLn "Waiting"
cmd @@ chan <- recv chan
lift $ putStrLn ("Received " ++ show cmd)
lift $ sleep 1
lift $ putStrLn "Sending answer"
if cmd
then do chan <- send chan 'a'
close chan
else do chan <- send chan "Foo"
close chan
lmain : Any IO ()
lmain
= do chan <- Channel.fork testServer
testClient chan
main : IO ()
main = run lmain