Skip to content

Instantly share code, notes, and snippets.

@sordina
Last active December 18, 2015 02:58
Show Gist options
  • Save sordina/5714390 to your computer and use it in GitHub Desktop.
Save sordina/5714390 to your computer and use it in GitHub Desktop.
Overloaded Strings Example
{-# 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
@afonsomatos
Copy link

Thank you for the example, simple and self-explanatory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment