Skip to content

Instantly share code, notes, and snippets.

@err0r500
Last active September 5, 2018 12:51
Show Gist options
  • Save err0r500/71cb643c9d1649ea7ec7369e35d870f0 to your computer and use it in GitHub Desktop.
Save err0r500/71cb643c9d1649ea7ec7369e35d870f0 to your computer and use it in GitHub Desktop.
business logic
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
import Control.Monad.Identity
import Control.Monad.Trans.Either
data User = User
{ name :: String
, firstName :: String
} deriving (Show)
class Monad m => UserGetter m where
getName :: Int -> m (Either String String)
getFirstname :: Int -> m (Either String String)
class Monad m => BusinessLogic m where
getCompleteUser :: Int -> m (Either String User)
instance (UserGetter m, Monad m) => BusinessLogic m where
getCompleteUser id =do
n <- getName id
case n of
Left err -> return (Left err)
Right name -> do
fn <- getFirstname id
case fn of
Left err -> return (Left err)
Right firstName -> return $ Right (User name firstName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment