diff --git a/bower.json b/bower.json index 386c65d..71112b3 100644 --- a/bower.json +++ b/bower.json @@ -16,12 +16,12 @@ "output" ], "dependencies": { - "purescript-integers": "^3.1.0", - "purescript-strings": "^3.3.0", - "purescript-foldable-traversable": "^3.4.0", - "purescript-lists": "^4.9.0" + "purescript-integers": "^4.0.0", + "purescript-strings": "^4.0.1", + "purescript-foldable-traversable": "^4.1.1", + "purescript-lists": "^5.3.0" }, "devDependencies": { - "purescript-psci-support": "^3.0.0" + "purescript-psci-support": "^4.0.0" } } diff --git a/package.json b/package.json index de8749d..e7a884d 100644 --- a/package.json +++ b/package.json @@ -24,9 +24,9 @@ }, "homepage": "https://github.com/Thimoteus/purescript-coercible#readme", "dependencies": { - "purescript": "^0.11.6", + "pulp": "^12.3.0", + "purescript": "^0.12.1", "purescript-psa": "^0.5.1", - "rimraf": "^2.6.1", - "pulp": "^11.0.2" + "rimraf": "^2.6.1" } } diff --git a/src/Control/Coercible.purs b/src/Control/Coercible.purs index ccd0b1c..c78aded 100644 --- a/src/Control/Coercible.purs +++ b/src/Control/Coercible.purs @@ -9,56 +9,49 @@ import Data.Foldable (foldMap) import Data.Int (toNumber) import Data.List (List(..), (:), reverse) import Data.Maybe (Maybe(..)) -import Data.String (fromCharArray, toCharArray, uncons) +import Data.String (CodePoint, codePointFromChar, fromCodePointArray, toCodePointArray, uncons) class Coercible a b where coerce :: a -> b -instance coercibleId :: Coercible a a where - coerce = id - -instance coercibleUnit :: Coercible a Unit where - coerce _ = unit - -instance coercibleVoid :: Coercible Void a where - coerce = absurd - -instance coercibleImage :: Coercible a (b -> a) where - coerce = const - instance coercibleIntNumber :: Coercible Int Number where coerce = toNumber - -instance coercibleCharString :: Coercible Char String where - coerce = fromChar - -instance coercibleArrayCharString :: Coercible (Array Char) String where - coerce = fromCharArray - -instance coercibleStringArrayChar :: Coercible String (Array Char) where - coerce = toCharArray - -instance coercibleFunctor :: (Functor f, Coercible a b) => Coercible (f a) (f b) where +else instance coercibleCodePointString :: Coercible CodePoint String where + coerce = fromCodePoint +else instance coercibleCharCodePoint :: Coercible Char CodePoint where + coerce = codePointFromChar +else instance coercibleCharString :: Coercible Char String where + coerce = fromCodePoint <<< codePointFromChar +else instance coercibleArrayCodePointString :: Coercible (Array CodePoint) String where + coerce = fromCodePointArray +else instance coercibleArrayCharString :: Coercible (Array Char) String where + coerce = fromCodePointArray <<< map codePointFromChar +else instance coercibleStringArrayCodePoint :: Coercible String (Array CodePoint) where + coerce = toCodePointArray +else instance coercibleFunctor :: (Functor f, Coercible a b) => Coercible (f a) (f b) where coerce = map coerce - -instance coercibleApplicative :: Applicative f => Coercible a (f a) where +else instance coercibleApplicative :: Applicative f => Coercible a (f a) where coerce = pure - -instance coercibleBind :: Bind m => Coercible (m (m a)) (m a) where +else instance coercibleBind :: Bind m => Coercible (m (m a)) (m a) where coerce = join - -instance coercibleComonad :: Comonad m => Coercible (m a) a where +else instance coercibleComonad :: Comonad m => Coercible (m a) a where coerce = extract - -instance coercableListCharString :: Coercible (List Char) String where - coerce = foldMap fromChar - -instance coercibleStringListChar :: Coercible String (List Char) where +else instance coercableListCodePointString :: Coercible (List CodePoint) String where + coerce = foldMap fromCodePoint +else instance coercableListCharString :: Coercible (List Char) String where + coerce = foldMap (fromCodePoint <<< codePointFromChar) +else instance coercibleStringListCodePoint :: Coercible String (List CodePoint) where coerce = reverse <<< coerce' Nil where coerce' acc str = case uncons str of Just { head, tail } -> coerce' (head : acc) str _ -> acc +else instance coercibleUnit :: Coercible a Unit where + coerce _ = unit +else instance coercibleVoid :: Coercible Void a where + coerce = absurd +else instance coercibleImage :: Coercible a (b -> a) where + coerce = const -fromChar :: Char -> String -fromChar c = fromCharArray [c] +fromCodePoint :: CodePoint -> String +fromCodePoint c = fromCodePointArray [c] diff --git a/test/Main.purs b/test/Main.purs index 091f992..3616918 100644 --- a/test/Main.purs +++ b/test/Main.purs @@ -1,11 +1,11 @@ module Test.Main where import Prelude -import Control.Monad.Eff (Eff) -import Control.Monad.Eff.Console (CONSOLE, logShow) -import Data.List ((:), List(Nil)) import Control.Coercible (class Coercible, coerce) +import Data.List ((:), List(Nil)) +import Effect (Effect) +import Effect.Class.Console (logShow) data N = Z | S N @@ -16,11 +16,10 @@ instance showN :: Show N where instance coerceNInt :: Coercible N Int where coerce Z = 0 coerce (S n) = 1 + coerce n - -instance coerceNString :: Coercible N String where +else instance coerceNString :: Coercible N String where coerce = show -main :: forall e. Eff (console :: CONSOLE | e) Unit +main :: Effect Unit main = do let three = S (S (S Z)) logShow $ coerce three :: String