Skip to content
Browse files

Renamed type class NumC to Num, it represents an actual type class, n…

…ot a data type!
  • Loading branch information...
1 parent 1b1424e commit 96a4315463fc86ea12a17afcb0ebf97a40e636e1 @tomlokhorst committed
Showing with 44 additions and 50 deletions.
  1. +1 −1 AwesomePrelude.cabal
  2. +5 −5 src/Generic/Data/List.hs
  3. +30 −0 src/Generic/Data/Num.hs
  4. +0 −31 src/Generic/Data/Number.hs
  5. +2 −2 src/Generic/Prelude.hs
  6. +6 −11 src/Lang/JavaScript.hs
View
2 AwesomePrelude.cabal
@@ -34,7 +34,7 @@ library
Generic.Data.Eq
Generic.Data.List
Generic.Data.Maybe
- Generic.Data.Number
+ Generic.Data.Num
Generic.Data.Ord
Generic.Data.Tuple
Generic.Prelude,
View
10 src/Generic/Data/List.hs
@@ -5,7 +5,7 @@ module Generic.Data.List where
import Prelude ()
import Generic.Data.Bool
import Generic.Data.Eq
-import Generic.Data.Number
+import Generic.Data.Num
import Generic.Data.Ord
import Generic.Control.Function
import Generic.Control.Functor
@@ -37,16 +37,16 @@ singleton a = a `cons` nil
foldr :: (FunC j, ListC j) => (j a -> j b -> j b) -> j b -> j [a] -> j b
foldr f b xs = fix (\r -> lam (list b (\y ys -> f y (r `app` ys)))) `app` xs
-replicate :: (ListC j, NumC j, Eq j Num, BoolC j, FunC j) => j Num -> j a -> j [a]
+replicate :: (ListC j, Eq j a, BoolC j, FunC j, Num j a) => j a -> j b -> j [b]
replicate n a = fix (\r -> lam (\y -> bool nil (a `cons` (r `app` (y - 1))) (y == 0))) `app` n
(++) :: (FunC j, ListC j) => j [a] -> j [a] -> j [a]
xs ++ ys = foldr cons ys xs
-length :: (FunC j, NumC j, ListC j) => j [a] -> j Num
-length = foldr (\_ -> (+1)) 0
+genericLength :: (FunC j, ListC j, Num j a) => j [b] -> j a
+genericLength = foldr (\_ -> (+1)) 0
-sum :: (FunC j, NumC j, ListC j) => j [Num] -> j Num
+sum :: (FunC j, ListC j, Num j a) => j [a] -> j a
sum = foldr (+) 0
filter :: (ListC j, BoolC j, FunC j) => (j a -> j Bool) -> j [a] -> j [a]
View
30 src/Generic/Data/Num.hs
@@ -0,0 +1,30 @@
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, UndecidableInstances #-}
+
+module Generic.Data.Num where
+
+import Prelude ()
+import qualified Prelude
+
+infixl 6 +
+infixl 7 *
+infixl 7 /
+infixl 6 -
+
+class Num j a where
+ (+) :: j a -> j a -> j a
+ (-) :: j a -> j a -> j a
+ (*) :: j a -> j a -> j a
+ (/) :: j a -> j a -> j a
+ fromInteger :: Prelude.Integer -> j a
+
+-- Terrible hack to get number literals working.
+
+instance Prelude.Show (j a) where show _ = "num"
+instance Prelude.Eq (j a) where
+instance Num j a => Prelude.Num (j a) where
+ (+) = Prelude.undefined
+ (*) = Prelude.undefined
+ abs = Prelude.undefined
+ signum = Prelude.undefined
+ fromInteger = fromInteger
+
View
31 src/Generic/Data/Number.hs
@@ -1,31 +0,0 @@
-{-# LANGUAGE EmptyDataDecls, FlexibleInstances #-}
-
-module Generic.Data.Number where
-
-import Prelude ()
-import qualified Prelude
-
-infixl 6 +
-infixl 7 *
-infixl 7 /
-infixl 6 -
-
-data Num
-class NumC j where
- (+) :: j Num -> j Num -> j Num
- (-) :: j Num -> j Num -> j Num
- (*) :: j Num -> j Num -> j Num
- (/) :: j Num -> j Num -> j Num
- num :: Prelude.Integer -> j Num
-
--- Terrible hack to get number literals working.
-
-instance Prelude.Show (j Num) where show _ = "num"
-instance Prelude.Eq (j Num) where
-instance NumC j => Prelude.Num (j Num) where
- (+) = Prelude.undefined
- (*) = Prelude.undefined
- abs = Prelude.undefined
- signum = Prelude.undefined
- fromInteger = num
-
View
4 src/Generic/Prelude.hs
@@ -13,7 +13,7 @@ module Generic.Prelude
, module Generic.Data.Eq
, module Generic.Data.List
, module Generic.Data.Maybe
-, module Generic.Data.Number
+, module Generic.Data.Num
, module Generic.Data.Ord
, module Generic.Data.Tuple
)
@@ -33,7 +33,7 @@ import Generic.Data.Either
import Generic.Data.Eq
import Generic.Data.List
import Generic.Data.Maybe
-import Generic.Data.Number
+import Generic.Data.Num
import Generic.Data.Ord
import Generic.Data.Tuple
View
17 src/Lang/JavaScript.hs
@@ -2,14 +2,7 @@
module Lang.JavaScript where
-import Generic.Control.Function
-import Generic.Data.Bool
-import Generic.Data.Either
-import Generic.Data.Eq
-import Generic.Data.List hiding ((++))
-import Generic.Data.Maybe
-import Generic.Data.Number
-import Generic.Data.Tuple
+import Generic.Prelude hiding ((++))
import Lang.Value
import Prelude ((++))
import qualified Prelude
@@ -32,12 +25,14 @@ instance BoolC (Val JS) where
false = Con "false"
bool x y z = fun3 "bool" (\[t, e, b] -> b ++ " ? " ++ t ++ "(/*force*/) : " ++ e ++ "(/*force*/)") (lam (const x)) (lam (const y)) z
-instance NumC (Val JS) where
+data Number
+
+instance Num (Val JS) Number where
(+) = fun2 "add" (\[a, b] -> a ++ " + " ++ b)
(-) = fun2 "sub" (\[a, b] -> a ++ " - " ++ b)
(*) = fun2 "mul" (\[a, b] -> a ++ " * " ++ b)
(/) = fun2 "div" (\[a, b] -> a ++ " / " ++ b)
- num x = Con (Prelude.show x)
+ fromInteger x = Con (Prelude.show x)
instance MaybeC (Val JS) where
nothing = Con "{ nothing : 1 }"
@@ -64,7 +59,7 @@ instance Eq (Val JS) Bool where
(==) = fun2 "eq" (\[a, b] -> a ++ " == " ++ b)
(/=) = fun2 "neq" (\[a, b] -> a ++ " /= " ++ b)
-instance Eq (Val JS) Num where
+instance Eq (Val JS) Number where
(==) = fun2 "eq" (\[a, b] -> a ++ " == " ++ b)
(/=) = fun2 "neq" (\[a, b] -> a ++ " /= " ++ b)

0 comments on commit 96a4315

Please sign in to comment.
Something went wrong with that request. Please try again.