roxxik 2017-02-01 00:05:32
`<~` ?
roxxik 2017-02-01 00:05:35
:t (<~)
lambdabot 2017-02-01 00:05:37
MonadState s m => ASetter s s a b -> m b -> m ()
systadmin 2017-02-01 00:06:03
hi
roxxik 2017-02-01 00:06:16
as in `instAt (ptr' + av) <~ instAt (ptr' + bv)`
roxxik 2017-02-01 00:06:39
wait...
roxxik 2017-02-01 00:07:02
as in `instAt (ptr' + av) <~ use $ instAt (ptr' + bv)`
roxxik 2017-02-01 00:07:08
something like that
roxxik 2017-02-01 00:07:50
generally `do { x <- a; l .= x }` <=> `l <~ a`
roxxik 2017-02-01 00:10:01
tsahyt: TreeT would be something like TreeT m a = m (Maybe (TreeT m a, a, TreeT m a))
roxxik 2017-02-01 00:10:23
just like ListT m a = m (Maybe (a, ListT m a))
roxxik 2017-02-01 00:11:27
(depending on your choice of Tree, this one is `data Tree a = Tip | Node (Tree a) a (Tree a)`)
phz_ 2017-02-01 00:12:37
:t (<~)
lambdabot 2017-02-01 00:12:39
MonadState s m => ASetter s s a b -> m b -> m ()
phz_ 2017-02-01 00:12:44
ah, lens…
phz_ 2017-02-01 00:13:29
:t (<%)
lambdabot 2017-02-01 00:13:32
error:
lambdabot 2017-02-01 00:13:32
• Variable not in scope: <%
lambdabot 2017-02-01 00:13:32
• Perhaps you meant one of these:
phz_ 2017-02-01 00:13:39
I thought it'd exist :)
roxxik 2017-02-01 00:13:50
what should it do?
roxxik 2017-02-01 00:14:04
:t (%=)
lambdabot 2017-02-01 00:14:06
MonadState s m => ASetter s s a b -> (a -> b) -> m ()
systadmin 2017-02-01 00:14:23
Is there a way to lower case all letters in a string?
roxxik 2017-02-01 00:14:31
:t tolower
lambdabot 2017-02-01 00:14:34
error:
lambdabot 2017-02-01 00:14:34
• Variable not in scope: tolower
lambdabot 2017-02-01 00:14:34
• Perhaps you meant 'toLower' (imported from Data.Char)
roxxik 2017-02-01 00:14:38
:t toLower
lambdabot 2017-02-01 00:14:40
Char -> Char
phz_ 2017-02-01 00:14:45
yeah I know %=
phz_ 2017-02-01 00:15:00
:t map toLower
roxxik 2017-02-01 00:15:00
systadmin: a String is just a List of Char
lambdabot 2017-02-01 00:15:03
[Char] -> [Char]
systadmin 2017-02-01 00:15:30
So I use toLower?
phz_ 2017-02-01 00:15:33
> map toLower "HEY!"
lambdabot 2017-02-01 00:15:35
"hey!"
systadmin 2017-02-01 00:16:42
I'm just trying to solve this Kata https://www.codewars.com/kata/makelowercase/train/haskell
roxxik 2017-02-01 00:17:20
phz_: `(<%) :: MonadState s m => ASetter s s a b -> (a -> m b) -> m ()` ?
roxxik 2017-02-01 00:17:56
this does not make much sense
roxxik 2017-02-01 00:19:04
(<%) :: MonadState s m => ALens s s a b -> (a -> m b) -> m ()
roxxik 2017-02-01 00:19:24
meh
thatguy 2017-02-01 00:19:54
systadmin, you should take a look at the map function too
systadmin 2017-02-01 00:20:29
map function?
systadmin 2017-02-01 00:20:32
:t map
lambdabot 2017-02-01 00:20:34
(a -> b) -> [a] -> [b]
systadmin 2017-02-01 00:21:25
What's map supposed to do?
Cale 2017-02-01 00:21:51
Well, it takes a function, and a list, and it applies the function to each of the elements of the list, obtaining a list of the results
Axman6 2017-02-01 00:21:54
what does its type say?
Axman6 2017-02-01 00:22:08
> map show [1,2,3]
lambdabot 2017-02-01 00:22:11
["1","2","3"]
Axman6 2017-02-01 00:22:20
> map (*7) [1,2,3]
lambdabot 2017-02-01 00:22:22
[7,14,21]
systadmin 2017-02-01 00:22:24
Cale: so it puts all of it's outputs in a list?
Axman6 2017-02-01 00:22:28
> map even [1,2,3]
lambdabot 2017-02-01 00:22:30
[False,True,False]
Cale 2017-02-01 00:22:48
^^ see the examples from Axman6
systadmin 2017-02-01 00:23:07
> map odd [1,2,3]
lambdabot 2017-02-01 00:23:10
[True,False,True]
Cale 2017-02-01 00:23:18
> map length ["here", "are", "some", "words"]
lambdabot 2017-02-01 00:23:21
[4,3,4,5]
Cale 2017-02-01 00:23:46
> map reverse ["here", "are", "some", "words"]
lambdabot 2017-02-01 00:23:49
["ereh","era","emos","sdrow"]
systadmin 2017-02-01 00:24:13
How can I fix this piece of code? http://lpaste.net/351862
Cale 2017-02-01 00:24:38
multiply a b = a * b
systadmin 2017-02-01 00:24:55
Cale: on line 5?
Cale 2017-02-01 00:25:40
Well, that's probably what you want, anyway. You could also change the type signature so that your definition would fit
Cale 2017-02-01 00:26:09
Is this homework?
Axman6 2017-02-01 00:26:16
you don't need to use return everywhere in haskell, in fact it has a very specific meaning, which is wuite different to other languages
systadmin 2017-02-01 00:26:45
Just practicing
Cale 2017-02-01 00:26:51
ah, okay
systadmin 2017-02-01 00:26:51
Self-teaching
systadmin 2017-02-01 00:27:02
Programming is a hobby for me
Cale 2017-02-01 00:27:32
So, yeah, you can get rid of the do on line 4, and the return $ on line 5
phz_ 2017-02-01 00:27:45
systadmin: import Data.Char ( toLower )
Cale 2017-02-01 00:27:48
and maybe just move the a * b up to the previous line, though that doesn't actually matter
phz_ 2017-02-01 00:27:50
makeLowerCase = map toLower
phz_ 2017-02-01 00:27:52
not that hard :P
systadmin 2017-02-01 00:28:04
Oh...
systadmin 2017-02-01 00:28:13
Why didn't I see this? lol
systadmin 2017-02-01 00:28:40
The fix to the broken piece of code was so simple but I didn't see it
thatguy 2017-02-01 00:32:24
if I have newtype T a = T a deriving (Num), does it mean I can only use T for a Num type?
thatguy 2017-02-01 00:33:12
or another problem, I thought newtype is used as a type alias, why would one define a type alias newtype T a = Ta for an polymorphic type a?
opqdonut 2017-02-01 00:35:04
thatguy: I'm pretty sure that derives an instance "Num a => Num (T a)"
opqdonut 2017-02-01 00:35:22
thatguy: so if a is a Num, T a is a Num too. but you can use T Bool if you want
phz_ 2017-02-01 00:35:52
you can use for any a, thatguy.
opqdonut 2017-02-01 00:35:53
thatguy: as for why would one define that, perhaps to have an alternative instance, like "Ord a => Ord (T a)"
phz_ 2017-02-01 00:36:05
that just means you provide an instance for Num
phz_ 2017-02-01 00:36:30
you can do T "foo" if you want to
phz_ 2017-02-01 00:36:55
restricting types that can be used in a type can be possible, but you have to put a constraint :)
thatguy 2017-02-01 00:36:59
but how would an instance for Num look for T "foo"?
Axman6 2017-02-01 00:37:05
thatguy: the instance would look like instance Num a => Num (T a) where T a + T b = T (a+b); negate (T a) = T (negate a) etc.
phz_ 2017-02-01 00:37:10
thatguy: it's forbidden
phz_ 2017-02-01 00:37:17
because when you use the deriving system
Axman6 2017-02-01 00:37:21
newtypes are not type aliases, type creates aliases
phz_ 2017-02-01 00:37:30
it automatically implies the correct constraints
phz_ 2017-02-01 00:37:32
in your case
phz_ 2017-02-01 00:37:47
instance (Num a) => Num (T a)
thatguy 2017-02-01 00:38:18
ah ok so in deriving Num I already put the constraint that I can only use Num types?
thatguy 2017-02-01 00:38:26
T "foo" would give me an error then
phz_ 2017-02-01 00:38:47
what you thought would happen is actually enabled with the extension DatatypeContexts
phz_ 2017-02-01 00:38:50
and it would be:
phz_ 2017-02-01 00:39:05
newtype Num a => T a = T a deriving …
merijn 2017-02-01 00:39:14
DatatypeContexts is an awful idea and you shouldn't use it nor recommend other people use it
Axman6 2017-02-01 00:39:16
thatguy: the constraint is on the _instance_, not on T. you can put whatever you want in the T constructor, but you can only use functions on Num when the type inside the T alsi instanciates Num
phz_ 2017-02-01 00:39:18
in that case, you wouldn't be able to create a T a if a doesn'it implement Num
phz_ 2017-02-01 00:39:28
merijn: I don't see why.
phz_ 2017-02-01 00:39:31
it has uses.
eklavya 2017-02-01 00:39:40
in wai logger "requestBody request" always returns an empty ByteString, please help
merijn 2017-02-01 00:39:45
phz_: There is a reason DatatypeContext *was* Haskell98 and dropped in Haskell2010
phz_ 2017-02-01 00:39:45
especially for associated types.
Axman6 2017-02-01 00:39:46
it basically doesn't have any good uses
merijn 2017-02-01 00:40:01
phz_: The only reason it exists as extension is for backwards compatibility with Haskell98
haskelllord69 2017-02-01 00:40:06
as a newbie ive seen the compiler recommend it to me many times, but it was always because I was doing something wrong
Axman6 2017-02-01 00:40:31
eklavya: can you share the code? you've not given enough info the be able to help
thatguy 2017-02-01 00:40:35
am I just completly confused or are some of you saying I could put a non-Num inside T and others say I couldn't?
merijn 2017-02-01 00:40:37
haskelllord69: "the compiler"? You mean GHC? As opposed to what?
eklavya 2017-02-01 00:40:41
Axman6: sorry yes
phz_ 2017-02-01 00:40:42
merijn: how would you create a type with a type variable that must have an implementation of a typeclass?
eklavya 2017-02-01 00:40:46
I was pasting
merijn 2017-02-01 00:40:57
phz_: You wouldn't, because that serves no practical purpose
merijn 2017-02-01 00:41:10
phz_: What would such a thing accomplish?
phz_ 2017-02-01 00:41:10
how did you come to that conclusion?
phz_ 2017-02-01 00:41:26
merijn: use associated types, mostly
haskelllord69 2017-02-01 00:41:46
yeah i mean ghc, sometimes it will say "turn on DatatypeContext" but its usually because i mistyped my types in some way
merijn 2017-02-01 00:41:47
phz_: Like how?
cocreature 2017-02-01 00:41:54
phz_: you are only restricting your type unnecessarily. putting the constraints on the functions that operate on a type is strictly more powerful
eklavya 2017-02-01 00:42:07
Axman6: http://lpaste.net/351863
phz_ 2017-02-01 00:42:18
data Foo a = Foo { dim :: Dim a } -- how to do you create such a type without the constraint?
phz_ 2017-02-01 00:42:28
if Dim changes for the instance of a?
merijn 2017-02-01 00:42:38
haskelllord69: Because there's lots of extensions and GHC tries to be helpful in case you accidentally forgot to enable one. It's just not always great about being right
phz_ 2017-02-01 00:42:42
cocreature: I'm talking about types
thatguy 2017-02-01 00:42:43
ah wait
phz_ 2017-02-01 00:42:43
not functions
merijn 2017-02-01 00:42:47
phz_: Why wouldn't that exact code not work?
haskelllord69 2017-02-01 00:42:57
merijin: Right :) I figured that one out pretty fast
merijn 2017-02-01 00:42:59
eh, ignore one negation there
phz_ 2017-02-01 00:43:02
merijn: because you don't know what Dim a is if you don't have the instance
phz_ 2017-02-01 00:43:06
so you need the constraint
merijn 2017-02-01 00:43:19
phz_: I don't see any instance or constraint there
phz_ 2017-02-01 00:43:26
if Dim is an associated type in the typeclass defined by whatever typeclass
merijn 2017-02-01 00:43:29
phz_: Note that associated types are not tied to typeclasses at all
Axman6 2017-02-01 00:43:30
this is something you tend to see more in GADTs
phz_ 2017-02-01 00:43:34
wait
thatguy 2017-02-01 00:43:36
Am I understanding this right now: newtype T a = T a deriving Num would create two data constructors? One T :: a -> T a and one T :: Num a => a -> T a ?
merijn 2017-02-01 00:43:38
phz_: They're just funny syntax for open type families
phz_ 2017-02-01 00:43:40
I have a production example
phz_ 2017-02-01 00:43:47
though it's not Haskell, it's Rust, but trait's are very similar
thatguy 2017-02-01 00:43:49
And haskell uses the "stronger" one when applicable
cocreature 2017-02-01 00:43:57
thatguy: no there is only one constructor
thatguy 2017-02-01 00:44:21
hmm I somehow have a hard time understanding this
phz_ 2017-02-01 00:44:31
https://github.com/phaazon/luminance-rs/blob/master/src/texture.rs#L270
phz_ 2017-02-01 00:44:36
look at the field "size"
merijn 2017-02-01 00:44:38
thatguy: I'm guessing because you're assuming instances are tied to data
phz_ 2017-02-01 00:44:42
without the constraint of D
cocreature 2017-02-01 00:44:44
thatguy: a -> T a, does not mean that a can't be an instance of something, it only means that it doesn't _have to be_ an instance of something
phz_ 2017-02-01 00:44:45
I couldn't have that.