-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A somewhat working version of deriving via & co.
Needs more work for correct handling of super-classes.
- Loading branch information
Showing
8 changed files
with
5,459 additions
and
5,331 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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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,69 @@ | ||
module Via where | ||
|
||
newtype B = B Bool | ||
deriving newtype Eq | ||
|
||
newtype N = N Int | ||
deriving newtype (Eq, Ord) | ||
deriving stock (Show) | ||
deriving newtype Num | ||
|
||
data Id a = Id a | ||
deriving stock Eq | ||
|
||
newtype BI = BI (Id Int) | ||
deriving newtype Eq | ||
|
||
newtype Id2 a = Id2 (Id a) | ||
deriving newtype Eq | ||
|
||
------ | ||
|
||
import Numeric | ||
|
||
newtype Hex a = Hex a | ||
|
||
instance (Integral a, Show a) => Show (Hex a) where | ||
show (Hex a) = "0x" ++ showHex a "" | ||
|
||
newtype Unicode = U Int | ||
deriving Show via (Hex Int) | ||
|
||
-- >>> euroSign | ||
-- 0x20ac | ||
euroSign :: Unicode | ||
euroSign = U 0x20ac | ||
|
||
------- | ||
|
||
class SPretty a where | ||
sPpr :: a -> String | ||
default sPpr :: Show a => a -> String | ||
sPpr = show | ||
|
||
data S = S String | ||
deriving stock Show | ||
deriving anyclass SPretty | ||
|
||
------- | ||
|
||
main :: IO () | ||
main = do | ||
print $ B True == B True | ||
|
||
let x = N 1 | ||
y = N 2 | ||
print $ x == x | ||
print $ x == y | ||
print $ x < y | ||
print $ x + y | ||
|
||
print $ BI (Id 1) == BI (Id 1) | ||
|
||
print $ Id2 (Id False) == Id2 (Id False) | ||
|
||
print euroSign | ||
|
||
print $ sPpr $ S "hello" | ||
|
||
putStrLn "done" |
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,10 @@ | ||
True | ||
True | ||
False | ||
True | ||
N 3 | ||
True | ||
True | ||
0x20AC | ||
"S \"hello\"" | ||
done |