kubunto 2017-03-02 05:46:13
nitrix: why
nitrix 2017-03-02 05:46:25
Again it's probably best to build a minimal intuition of how to use and create functors... at least to be able to write simple programs, and then slowly learn what is and isn't a functor.
nitrix 2017-03-02 05:46:32
kubunto: The explanation will fly above your head but:
nitrix 2017-03-02 05:47:16
kubunto: The kind of `Tree a b` is `* -> * -> *`. It's a type constructor that expects two other concrete types and produces a concrete type.
nitrix 2017-03-02 05:47:33
kubunto: class Functor (f :: * -> *) where fmap :: (a -> b) -> f a -> f b
kubunto 2017-03-02 05:48:02
it isnt (a b -> c d)
nitrix 2017-03-02 05:48:05
kubunto: The `f` required for `Functor` needs to be a type constructor with kind `* -> *` (taking only a single type as argument, not two).
nitrix 2017-03-02 05:48:27
kubunto: Your notation isn't correct but I get what you're trying to describe.
nitrix 2017-03-02 05:48:30
That'd be a Bifunctor.
kubunto 2017-03-02 05:48:52
sounds like a headache
nitrix 2017-03-02 05:48:58
And they work differently. Their interface is much different too.
nitrix 2017-03-02 05:49:03
bimap f g v
nitrix 2017-03-02 05:49:18
For Bifunctors, there are two transformation functions, rather than one.
nitrix 2017-03-02 05:50:40
I can understand the reaction. Without proper understanding of Functor, it's probably hard to conceptualize why would someone even want Bifunctor, or some infinite functor.
kubunto 2017-03-02 05:51:01
nitrix: whats wrong with this: http://lpaste.net/353133
nitrix 2017-03-02 05:51:14
I'm afraid that reasoning is due to not understanding what functors are used for. You might be conflating records / product types, with functors, which promises something else entirely.
nitrix 2017-03-02 05:51:49
kubunto: But, we're slowly building an intuition now, so that's awesome :D
nitrix 2017-03-02 05:53:50
kubunto: Checking
nitrix 2017-03-02 05:54:06
That seems doable.
nitrix 2017-03-02 05:54:19
@let data Equation d = Digit d | Operator d (Equation d ) (Equation d)
lambdabot 2017-03-02 05:54:22
Defined.
nitrix 2017-03-02 05:54:45
@let instance Functor Equation where fmap f (Digit d) = Digit (f d); fmap f (Operator a b c) = Operator a (fmap f b) (fmap f c)
lambdabot 2017-03-02 05:54:48
.L.hs:174:47: error:
lambdabot 2017-03-02 05:54:48
• Couldn't match type 'b' with 'a'
lambdabot 2017-03-02 05:54:48
'b' is a rigid type variable bound by
kubunto 2017-03-02 05:55:00
yea thats what i got
glguy 2017-03-02 05:55:34
The f for functor doesn't even need to be a type constructor
glguy 2017-03-02 05:55:52
Something like 'Either ()' will do, too
nitrix 2017-03-02 05:56:24
glguy: That has kind `* -> *`, no? Isn't that a type constructor?
glguy 2017-03-02 05:56:36
No, Either and () are type constructors
glguy 2017-03-02 05:56:48
Type constructor is a category of names, nothing to do with kinds
nitrix 2017-03-02 05:56:53
glguy: Ah interesting point of view.
glguy 2017-03-02 05:57:16
It's just the definition, not really a point of view
nitrix 2017-03-02 05:57:41
glguy: Is there a useful name to describe `Either ()` ?
nitrix 2017-03-02 05:57:41
Partially applied type constructor :3 ?
glguy 2017-03-02 05:57:41
It's a type with kind * -> *
Cale 2017-03-02 05:57:41
It's a type of kind * -> *
nitrix 2017-03-02 05:57:41
Ah okay.
kubunto 2017-03-02 05:57:44
nitrix: i know the either thing
kubunto 2017-03-02 05:57:55
left a | right b
Cale 2017-03-02 05:57:56
You could call it a type function if you like
nitrix 2017-03-02 05:58:30
Cale: I had always associated type construtor with type function mentally, but I now see that a distinction is needed.
glguy 2017-03-02 05:59:56
It's analogous to the value level with constructors Just and True where types don't factor in
nitrix 2017-03-02 06:00:00
glguy: Does this has a correlation with FlexibleInstances?
glguy 2017-03-02 06:00:37
I suppose. Haskell says that instances should specify one type constructor applied to zero or more type variables
nitrix 2017-03-02 06:00:41
glguy: e.g. GHC whining that the pattern for the instance must have the form `T a1 ... am` ?
glguy 2017-03-02 06:00:52
Flexible instances loosens that to allow being applied to other type constructors
kubunto 2017-03-02 06:01:03
nitrix: still cant get the recursive part of the fmap to work
glguy 2017-03-02 06:01:03
or even other non-variable types
glguy 2017-03-02 06:01:11
like (f a)
nitrix 2017-03-02 06:01:11
So isn't it okay to call it a type constructor?
glguy 2017-03-02 06:01:28
To call what a type constructor?
nitrix 2017-03-02 06:01:59
Either applied on (), I doubt that it's less of a type constructor just because it's being applied an argument.
glguy 2017-03-02 06:02:07
No, it's still nothing to do with being a type constructor
glguy 2017-03-02 06:02:18
flexible instances looses the restrictions on making instances, not on what a type constructor is
glguy 2017-03-02 06:02:40
There are type constructors: Either Bool () (->), and there are type variables a b c d e...
glguy 2017-03-02 06:02:51
from those you can form more interesting types via application
nitrix 2017-03-02 06:03:23
I see, what you're saying is the report would just say `T` as the pattern if `Either ()` was a type constructor and get away with just saying it has to be a type constructor.
nitrix 2017-03-02 06:03:59
Instead, it specifies `T a1 .. am` such that you need a type constructor AND one or more type variables.
glguy 2017-03-02 06:04:08
zero or more
nitrix 2017-03-02 06:04:18
Wait you said zero earlier. Why is the pattern `T a1 .. am` then?
glguy 2017-03-02 06:04:32
m can be 0
glguy 2017-03-02 06:04:40
Consider: Show Int
nitrix 2017-03-02 06:04:45
a1 .. a0 ?
glguy 2017-03-02 06:04:47
T is Int there
nitrix 2017-03-02 06:04:48
That's an odd range.
nitrix 2017-03-02 06:06:39
glguy: I'll try to remember.
nitrix 2017-03-02 06:08:19
glguy: Cale I appreciate the correction :)
mwilly 2017-03-02 06:09:35
ThisPasswordIsNotGood@All
kubunto 2017-03-02 06:09:45
hehe
kubunto 2017-03-02 06:10:03
nitrix: glguy still lost on the recursive fmap call
dgpratt 2017-03-02 06:10:07
not anymore it ain't
absence 2017-03-02 06:15:32
i'm using stack with lts-8.3 and get "GHC runtime linker: fatal error: I found a duplicate definition for symbol _js_decode_string" because it's defined in both aeson and json-stream, and then "ghc.EXE: panic! (the 'impossible' happened)". anyone seen this?
kubunto 2017-03-02 06:21:10
anyone know about recursive fmaping
mnoonan 2017-03-02 06:21:47
maybe?
mnoonan 2017-03-02 06:21:59
what are you trying to do?
kubunto 2017-03-02 06:22:24
i am trying to get this to work: http://lpaste.net/353133
jle` 2017-03-02 06:22:59
kubunto: we need to know the definition of Equation
kubunto 2017-03-02 06:23:28
jle`: see title
kubunto 2017-03-02 06:23:28
it is my bad but it is there
jle` 2017-03-02 06:23:32
ah i see.
jle` 2017-03-02 06:23:39
well, what is the error?
kubunto 2017-03-02 06:24:26
jle`: http://lpaste.net/353135
glguy 2017-03-02 06:25:19
kubunto: In the expression "Operator x (fmap f y) (fmap f z)", x has type 'a', but a value of type 'b' is needed
jle` 2017-03-02 06:25:34
yeah, i'd probably use different variable names
glguy 2017-03-02 06:26:27
so you need to think of a value with type 'b' to fit into "Operator _ (fmap f y) (fmap f z)"
kubunto 2017-03-02 06:27:30
got it
kubunto 2017-03-02 06:28:15
turned the x to (f x)
ski 2017-03-02 06:29:21
yes
ski 2017-03-02 06:29:46
(the error message indicated this position in the code -- "In the first argument of 'Operator', namely 'x'")
kubunto 2017-03-02 06:30:00
so fmap transforms a monad to a monad right?
jle` 2017-03-02 06:30:11
fmap transforms a function into a function
Sornaensis 2017-03-02 06:30:24
fmap applies a function to the contents of a functor
jle` 2017-03-02 06:30:27
it turns an (a -> b) into an (f a -> f b), for any Functor f
jle` 2017-03-02 06:31:35
it doesn't transform any monads. monads exist at the type level, not at the value level
kubunto 2017-03-02 06:31:46
where would a monad fit into a functor?
jle` 2017-03-02 06:31:49
monads are types, not values, so fmap can't really transform monads because it's a function that works on values
jle` 2017-03-02 06:32:18
monads are a subset of functors
jle` 2017-03-02 06:32:38
some functors are monads, like how some rectangles are squares
ski 2017-03-02 06:32:40
all monads are functors. some functors are monads, some aren't
kubunto 2017-03-02 06:34:15
so what is a monad?
Sornaensis 2017-03-02 06:34:41
@hoogle Monad
lambdabot 2017-03-02 06:34:44
Prelude class Applicative m => Monad m
lambdabot 2017-03-02 06:34:44
module Control.Monad
lambdabot 2017-03-02 06:34:44
Control.Monad class Applicative m => Monad m
monochrom 2017-03-02 06:35:01
"Maybe" is a monad. "IO" is a monad. etc etc.
Sornaensis 2017-03-02 06:35:19
kubunto: http://hackage.haskell.org/package/base-4.9.1.0/docs/Prelude.html#t:Monad
kubunto 2017-03-02 06:35:20
Either?
Sornaensis 2017-03-02 06:35:25
a Monad is a type that instances this class
Sornaensis 2017-03-02 06:35:31
see the 'minimal complete definition'
mauke 2017-03-02 06:35:32
a monad is a type constructor m
mauke 2017-03-02 06:35:34
with some functions
Sornaensis 2017-03-02 06:35:58
a Monad is an applicative and a functor with a definition for (>>=)
ski 2017-03-02 06:35:59
kubunto : `Either' is not a monad, but `Either e' is a monad, for any type `e'
Sornaensis 2017-03-02 06:36:01
:t (>>=)
mauke 2017-03-02 06:36:02
a monad takes a single type parameter, so Int can't be one (no parameter)
lambdabot 2017-03-02 06:36:04
Monad m => m a -> (a -> m b) -> m b
c_wraith 2017-03-02 06:36:09
kubunto, the Monad class abstracts over a particular pattern of composition. don't worry about the details - they actually aren't that important
glguy 2017-03-02 06:36:15
It's not necessary to be a type constructor to be a monad, 'Either a' is a Monad
mauke 2017-03-02 06:36:27
Either can't be one because it takes two parameters. but 'Either a' (for every type a) is a monad
mauke 2017-03-02 06:36:39
hmm. maybe "type constructor" is the wrong word
ski 2017-03-02 06:36:57
"type constructor" is used in two difference senses
mauke 2017-03-02 06:37:27
something of kind * -> * :-)
ski 2017-03-02 06:37:46
type function is a good term, i think :)
ski 2017-03-02 06:38:51
(`ReadS' is a monad, but is not an instance of `Monad')
monochrom 2017-03-02 06:39:16
In want of an oversimplified coarse dichotomy between kind * and other kinds. But oversimplified coarse dichotomies numb the mind.
mauke 2017-03-02 06:39:56
"parameterized type"
kubunto 2017-03-02 06:40:11
how would >>= be used on a maybe?
monochrom 2017-03-02 06:40:15
Just like the one between "values" and "functions" becomes confusing when higher-order functions appear.
monochrom 2017-03-02 06:40:45
Just 5 >>= (\x -> Just (x + x))
mauke 2017-03-02 06:41:37
> Nothing >>= \x -> return (show x)
lambdabot 2017-03-02 06:41:40
Nothing
mauke 2017-03-02 06:41:44
> Just [1,2,3] >>= \x -> return (show x)
lambdabot 2017-03-02 06:41:47
Just "[1,2,3]"
ski 2017-03-02 06:42:12
kubunto : one could say that a monad is a certain "pattern" that has been cropping up again and again, and once one recognizes the common pattern, one can write a couple of helper functions to avoid large swathes of repetitive boilerplate code (which would be easy to get a detail wrong here and there)
ski 2017-03-02 06:42:34
kubunto : perhaps "What the hell are Monads?" by Noel Winstanley in 1999 might interest you
monochrom 2017-03-02 06:43:09
There was an ancient small tribe whose number system was the coarse trichotomy "one, two, many".
mauke 2017-03-02 06:43:41
the thing about Monad is that the instances all seem wildly different. yet they all support the same basic interface
Sornaensis 2017-03-02 06:44:02
> let x = Just 1;y = Just 5;z = Just 10 in do { x' <- x; y' <- y; z' <- z; return $ z*y+x }
lambdabot 2017-03-02 06:44:06
error:
lambdabot 2017-03-02 06:44:06
• Ambiguous type variable 'a0' arising from a use of 'show_M467484464745...
lambdabot 2017-03-02 06:44:06
prevents the constraint '(Show a0)' from being solved.
monochrom 2017-03-02 06:44:21
Very "nice" for students, but very useless.
Sornaensis 2017-03-02 06:44:37
> let x = Just 1;y = Just 5;z = Just 10 in do { x' <- x; y' <- y; z' <- z; return $ z'*y'+x' }
Sornaensis 2017-03-02 06:44:39
derp
lambdabot 2017-03-02 06:44:40
Just 51
pikajude 2017-03-02 06:45:02
use liftA3 (\ x y z -> z * y + x)
kubunto 2017-03-02 06:45:03
what is >> used for?