forked from isovector/thinking-with-types
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upgrade to ghc 9.2.1 with design-tools
- Loading branch information
Showing
11 changed files
with
188 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CodeBlock ("",["haskell","ghci"],[]) "> serialized\nhello\nhello\nhello\nhello\nhello\nhello\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CodeBlock ("",["haskell","ghci"],[]) "> interleaved\nhehello\nhello\nhelllloo\n\nhello\nhello\n\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{-# LANGUAGE ImpredicativeTypes #-} | ||
{-# LANGUAGE NumDecimals #-} | ||
|
||
module ImpredicativeTypes where | ||
|
||
import Control.Concurrent | ||
import Control.Exception (bracket_) | ||
import Data.Foldable (for_) | ||
import Control.Monad (void) | ||
|
||
-- | Make a locking serializer | ||
makeSerial :: IO (forall a. IO a -> IO a) | ||
makeSerial = fmap locking newEmptyMVar | ||
|
||
-- | Make a locking serializer with a given lock | ||
locking :: MVar () -> (forall a. IO a -> IO a) | ||
locking lock = bracket_ (putMVar lock ()) (takeMVar lock) | ||
|
||
dump :: (IO () -> IO ()) -> IO () | ||
dump f = | ||
void $ forkIO $ | ||
for_ [0..2] $ const @_ @Int $ f $ putStrLn "hello" | ||
|
||
serialized :: IO () | ||
serialized = do | ||
makeSerial >>= \serial -> do | ||
dump serial | ||
dump serial | ||
|
||
threadDelay 1e5 | ||
|
||
|
||
interleaved :: IO () | ||
interleaved = do | ||
dump id | ||
dump id | ||
|
||
threadDelay 1e5 | ||
|
||
yo :: (forall a. [a] -> [a]) -> Int | ||
yo _ = 0 | ||
|
||
($$) :: (a -> b) -> a -> b | ||
g $$ a = g a | ||
|
||
blah :: Int | ||
blah = yo $$ reverse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
## Impredicative Types {.rev2} | ||
|
||
### Polytypes | ||
|
||
Types come in two varieties---*monotypes* and *polytypes.* Monotypes are those | ||
types that are entirely concrete, and polytypes are any types which contain a | ||
`forall` quantifier. Thus `Int -> Bool` is a monotype, but `forall a. a -> | ||
String` is a polytype. | ||
|
||
hello | ||
|
||
```{ghci=code/ImpredicativeTypes.hs} | ||
interleaved | ||
``` | ||
|
||
world | ||
|
||
```{ghci=code/ImpredicativeTypes.hs} | ||
serialized | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters