From 6b5154696d7481a04ad4cb4dfd979a8a9010dc40 Mon Sep 17 00:00:00 2001 From: Yu-Hsi Chiang Date: Sun, 1 Oct 2017 23:57:54 +0800 Subject: [PATCH] Add a `FromParam` instance for String. --- fn/src/Web/Fn.hs | 4 ++++ fn/test/Spec.hs | 2 ++ 2 files changed, 6 insertions(+) diff --git a/fn/src/Web/Fn.hs b/fn/src/Web/Fn.hs index 6b5ba7d..03ae8b1 100644 --- a/fn/src/Web/Fn.hs +++ b/fn/src/Web/Fn.hs @@ -423,6 +423,10 @@ instance FromParam Text where fromParam [x] = Right x fromParam [] = Left ParamMissing fromParam _ = Left ParamTooMany +instance {-# INCOHERENT #-} FromParam String where + fromParam [t] = Right (T.unpack t) + fromParam [] = Left ParamMissing + fromParam _ = Left ParamTooMany instance FromParam Int where fromParam [t] = case decimal t of Left _ -> Left ParamUnparsable diff --git a/fn/test/Spec.hs b/fn/test/Spec.hs index ce55a63..4fee779 100644 --- a/fn/test/Spec.hs +++ b/fn/test/Spec.hs @@ -170,6 +170,8 @@ main = hspec $ do describe "parameter parsing" $ do it "should parse Text" $ fromParam ["hello"] `shouldBe` Right ("hello" :: Text) + it "should parse String" $ + fromParam ["hello"] `shouldBe` Right ("hello" :: String) it "should parse Int" $ do fromParam ["1"] `shouldBe` Right (1 :: Int) fromParam ["2011"] `shouldBe` Right (2011 :: Int)