-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
26b9cea
commit 33a1141
Showing
3 changed files
with
29 additions
and
0 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,25 @@ | ||
import Data.Dynamic | ||
import Data.Foldable | ||
|
||
mixedList = | ||
[ toDyn True | ||
, toDyn (5 :: Integer) | ||
, toDyn "hey" | ||
] | ||
|
||
main = | ||
for_ mixedList $ \d -> | ||
putStrLn (message d) | ||
|
||
recognizeType d = | ||
asum | ||
[ (fromDynamic d :: Maybe Integer) >>= \x -> | ||
Just (show x ++ " is an integer") | ||
, (fromDynamic d :: Maybe Bool) >>= \x -> | ||
Just ("The answer is " ++ (if x then "yes" else "no")) | ||
] | ||
|
||
message d = | ||
case (recognizeType d) of | ||
Just x -> x | ||
Nothing -> "Unrecognized type: " ++ show (dynTypeRep d) |
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,3 @@ | ||
The answer is yes | ||
5 is an integer | ||
Unrecognized type: [Char] |
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