Skip to content

Instantly share code, notes, and snippets.

@josiah14
Created November 23, 2014 07:35
Show Gist options
  • Save josiah14/e4f2c6f5a2657a557b49 to your computer and use it in GitHub Desktop.
Save josiah14/e4f2c6f5a2657a557b49 to your computer and use it in GitHub Desktop.
Hmm. Haskell wont treat a (Functor f) => f String as a single value, so I can't make ((->) SomeType) into a Functor if the value returned by the Arrow is a Functor...
-- apply a style function to a shell prompt functor
-- e.g.
-- bold & fgColor red `style` gitCurrentBranch
style :: (String -> ShellPromptType -> String) -> ShellPromptSegment String
-> ShellPromptType -> ShellPromptSegment String
style f segment = \shType -> (flip f) shType <$> segment
-- this is fine
style' :: (String -> ShellPromptType -> String)
-> (ShellPromptType -> ShellPromptSegment String)
-> ShellPromptType -> ShellPromptSegment String
style' f makeSegment = flip f >>= \g shellType -> fmap g $ makeSegment shellType
-- this apparently is not. Compiler complains that it wants the type (String -> String) -> ShellPromptType -> b
-- for my lambda function there, but it gets (String -> String) -> ShellPromptType -> ShellPromptSegment String
-- instead. I guess 'b' is not allowed to be a functor?
instance Functor ((->) ShellPromptType) where
fmap f makeSegment = ((flip f) :: ShellPromptType -> String -> String)
>>= ((\g shellType -> fmap g $ makeSegment shellType)
:: (String -> String) -> ShellPromptType -> (ShellPromptSegment String))
@josiah14
Copy link
Author

LambdaLine/Shells/ShellPromptSegment.hs|81 col 30 error| Couldn't match type `ShellPromptType -> String'
||               with `ShellPromptSegment String'
|| Expected type: (String -> String) -> ShellPromptType -> b
||   Actual type: (String -> String)
||                -> ShellPromptType -> ShellPromptSegment String
|| In the second argument of `(>>=)', namely
||   `((\ g shellType -> fmap g $ makeSegment shellType) ::
||       (String -> String)
||       -> ShellPromptType -> (ShellPromptSegment String))'
|| In the expression:
||   ((flip f) :: ShellPromptType -> String -> String)
||   >>=
||     ((\ g shellType -> fmap g $ makeSegment shellType) ::
||        (String -> String)
||        -> ShellPromptType -> (ShellPromptSegment String))
|| In an equation for `fmap':
||     fmap f makeSegment
||       = ((flip f) :: ShellPromptType -> String -> String)
||         >>=
||           ((\ g shellType -> fmap g $ makeSegment shellType) ::
||              (String -> String)
||              -> ShellPromptType -> (ShellPromptSegment String))
LambdaLine/Shells/ShellPromptSegment.hs|81 col 56 error| Couldn't match type `[Char]' with `ShellPromptSegment String'
|| Expected type: ShellPromptSegment String
||   Actual type: a
|| In the return type of a call of `makeSegment'
|| In the second argument of `($)', namely `makeSegment shellType'
|| In the expression: fmap g $ makeSegment shellType

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