File tree Expand file tree Collapse file tree 1 file changed +58
-0
lines changed
Expand file tree Collapse file tree 1 file changed +58
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ {-# LANGUAGE UndecidableInstances #-}
3+ {-# LANGUAGE FlexibleInstances #-}
4+ {-# LANGUAGE GADTs #-}
5+ {-# LANGUAGE DataKinds #-}
6+ {-# LANGUAGE TypeOperators #-}
7+ {-# LANGUAGE KindSignatures #-}
8+
9+ {-# LANGUAGE MultiParamTypeClasses #-}
10+
11+ module Combination.MWE where
12+
13+ class Addable a b c where
14+ doAdd :: a -> b -> c
15+
16+ addera :: (Addable a b c ) => a -> b -> c
17+ addera = doAdd
18+
19+ -- instance (Addable Double Double Double) where
20+ -- doAdd = (+)
21+
22+ instance (Num v ) => Addable v v v where
23+ doAdd = (+)
24+
25+ data Container (d :: * ) (v :: * ) where
26+ ValContainer :: v -> Container d v
27+
28+ addCon :: (Addable v v v ) => Container d v -> Container d v -> Container d v
29+ addCon (ValContainer x) (ValContainer y) = ValContainer $ doAdd x y
30+
31+ v1 :: Container Bool Double
32+ v1 = ValContainer 2.0
33+ v2 :: Container Bool Double
34+ v2 = ValContainer 3.0
35+
36+ containerAdd :: (Addable a b c ) => Container d a ->
37+ Container d b ->
38+ Container d c
39+ containerAdd (ValContainer a) (ValContainer b) = ValContainer (doAdd a b)
40+
41+ v3 :: Container Bool Double
42+ v3 = containerAdd v1 v2
43+
44+
45+
46+
47+
48+
49+
50+
51+
52+
53+
54+
55+
56+
57+
58+
You can’t perform that action at this time.
0 commit comments