Last active
December 18, 2015 02:58
-
-
Save sordina/5714390 to your computer and use it in GitHub Desktop.
Overloaded Strings Example
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
{-# LANGUAGE OverloadedStrings #-} | |
import GHC.Exts ( IsString(..) ) | |
data Foo = A | B | Other String deriving Show | |
instance IsString Foo where | |
fromString "A" = A | |
fromString "B" = B | |
fromString xs = Other xs | |
tests :: [ Foo ] | |
tests = [ "A", "B", "Testing" ] | |
main :: IO () | |
main = mapM_ print tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for the example, simple and self-explanatory.