Search Haskell Channel Logs

Saturday, February 11, 2017

#haskell channel featuring boccato, reactormonk, AndreasK, dramforever, warrshrike, monad-mad,

AndreasK 2017-02-11 01:07:01
Are there cases where its better to manually use a case instead of fromMaybe?
reactormonk 2017-02-11 01:11:14
AndreasK, then you can also use a `maybe`.
AndreasK 2017-02-11 01:12:08
It's not my code and the linter was complaining, just wondering if anyone could think of a reason if changed case to fromMaybe there could break something
AndreasK 2017-02-11 01:12:18
Besides the unreadability ... :D
cocreature 2017-02-11 01:19:30
AndreasK: theoretically, if fromMaybe wasn't inlined the performance could be worse. but I would expect GHC to always inline this
monad-mad 2017-02-11 01:21:36
Hey guys
monad-mad 2017-02-11 01:21:44
a little help
monad-mad 2017-02-11 01:23:09
guys
monad-mad 2017-02-11 01:23:13
gais
monad-mad 2017-02-11 01:23:16
there?
cocreature 2017-02-11 01:23:21
monad-mad: just ask your question directly :)
monad-mad 2017-02-11 01:23:35
ok
monad-mad 2017-02-11 01:23:42
foo :: Maybe String foo = do x <- Just 3 y <- Just "!" Just (show x ++ y)
monad-mad 2017-02-11 01:23:56
sorry for weird formatting
cocreature 2017-02-11 01:24:25
@where lpaste
lambdabot 2017-02-11 01:24:25
http://lpaste.net/
cocreature 2017-02-11 01:24:29
you can paste your code there
monad-mad 2017-02-11 01:24:53
doing that
monad-mad 2017-02-11 01:25:01
anyway
monad-mad 2017-02-11 01:25:11
the last Just (x ++ y)
monad-mad 2017-02-11 01:25:19
can it be show x++y
monad-mad 2017-02-11 01:25:25
as i understand
monad-mad 2017-02-11 01:25:39
the last line is going to be returned
cocreature 2017-02-11 01:25:54
you are using do notation for Maybe so the last line has to be of type Maybe a
cocreature 2017-02-11 01:26:01
show x ++ y is of type String
monad-mad 2017-02-11 01:26:05
and return will convert show x ++ y into Just (show x ++ y)
monad-mad 2017-02-11 01:26:18
oh, so the last line is not automatically returned?
monad-mad 2017-02-11 01:26:35
I could do return (show x++y) can't I?
cocreature 2017-02-11 01:26:44
yes
cocreature 2017-02-11 01:26:55
but "return" is different from the return statement found in other languages
cocreature 2017-02-11 01:27:02
it's just an ordinary function
monad-mad 2017-02-11 01:27:03
http://lpaste.net/352365
cocreature 2017-02-11 01:27:04
:t return
lambdabot 2017-02-11 01:27:07
Monad m => a -> m a
monad-mad 2017-02-11 01:27:08
I know, I know
monad-mad 2017-02-11 01:27:40
in the Maybe monad , return x is defined as Just x
cocreature 2017-02-11 01:27:58
"return" it is not automagically inserted in the last line of a do block
reactormonk 2017-02-11 01:28:45
Not sure why it's called return, "lift" or "point" would have been a bit better, because distinct naming.
mangobot 2017-02-11 01:28:54
parser :: String -> [Figure] -> Int -> Int -> [Figure] means that the function takes a string returning a function that takes a figure int int and returns a figure?
monad-mad 2017-02-11 01:29:03
I understand how return works in haskell
monad-mad 2017-02-11 01:29:16
http://lpaste.net/352367
monad-mad 2017-02-11 01:29:25
the last line in that, calls return x
monad-mad 2017-02-11 01:29:47
which calls Maybe monad's return x, which is Just x
cocreature 2017-02-11 01:29:54
monad-mad: so what exactly is your question? return is not automatically inserted if that's what you're asking
monad-mad 2017-02-11 01:30:32
in the first code, I do return (show x++y) instead of Just (show x++y)
monad-mad 2017-02-11 01:30:39
It is correct, right
cocreature 2017-02-11 01:30:47
yep
monad-mad 2017-02-11 01:30:51
as return will convert it into Maybe
monad-mad 2017-02-11 01:31:02
Ok, thanks
monad-mad 2017-02-11 01:31:09
now my 2nd question
monad-mad 2017-02-11 01:31:18
what if I do return Nothing
monad-mad 2017-02-11 01:31:24
in the last line
monad-mad 2017-02-11 01:31:37
return x = Just x
cocreature 2017-02-11 01:31:47
monad-mad: then your do block has type "Maybe (Maybe a)"
monad-mad 2017-02-11 01:32:17
will result in an error then right
cocreature 2017-02-11 01:33:02
mangobot: not quite it means that parser is a function that takes a String and returns a function that takes a [Figure] and returns a function that takes an Int and returns a function that takes an Int and returns [Figure]
cocreature 2017-02-11 01:33:21
monad-mad: yep because your type signature says that it should have type Maybe Char
monad-mad 2017-02-11 01:33:41
thanks cocreature
monad-mad 2017-02-11 01:34:46
I am almost done with learnyouahaskell, can you suggest some other tutorials or blogs to help me
monad-mad 2017-02-11 01:35:43
\me is indebted to cocreature
dramforever 2017-02-11 01:35:52
https://github.com/bitemyapp/learnhaskell
dramforever 2017-02-11 01:36:30
That's basically THE beginner's free resource list
monad-mad 2017-02-11 01:37:29
thanks
monad-mad 2017-02-11 01:38:51
monads monoids applicatives and functors
monad-mad 2017-02-11 01:39:24
that's basically it right, in terms of mathematics
monad-mad 2017-02-11 01:40:06
If I can leverage these + know the basic syntax and semantics I am good to go right
dramforever 2017-02-11 01:40:07
You're oversimplifying
dramforever 2017-02-11 01:40:30
TBH these *are* basic syntax and semantics
monad-mad 2017-02-11 01:40:53
I was talking about pattern matching, let etc.
dramforever 2017-02-11 01:41:15
umm, you *don't* know what these are right?
dramforever 2017-02-11 01:41:48
Just go. Rest assured that you're good to go.
monad-mad 2017-02-11 01:41:57
I am currently done with the basics + everyting upto monads
monad-mad 2017-02-11 01:42:18
and with you guys' help I am pretty confident with monads too
warrshrike 2017-02-11 01:42:19
hey guys
warrshrike 2017-02-11 01:42:32
im doing a sudoku solver thing
boccato 2017-02-11 01:42:48
When I do "stack ghci" outside a project. To load a package, should I install it globally?
cocreature 2017-02-11 01:43:04
monad-mad: at this point I would recommend to just write some code and pick the rest up along the way. practise is important.
reactormonk 2017-02-11 01:43:34
warrshrike, there's an implementation in dpkg, if you're looking for one. :-P
dramforever 2017-02-11 01:43:37
Just, kinda try to remember monad isn't really much
warrshrike 2017-02-11 01:44:12
reactormonk: thanks buddy but I seek to Learn and Gain Enlightenment
monad-mad 2017-02-11 01:44:12
Yeah, that's what I thought. I like to be well versed in the basics *before* writing code
warrshrike 2017-02-11 01:44:17
Part 1: Implement the sudoku solver that takes a board and returns a -- solved board. Assume that a solution always exists. Use toElements, -- fromElements, and sudokuElements functions described below. sudoku :: Board -> Board sudoku b | b == inputBoard = solvedBoard | otherwise = error "sudoku not implemented"
warrshrike 2017-02-11 01:44:30
Im having some trouble getting what his is saying
dramforever 2017-02-11 01:44:38
monad-mad: Well I guess you should interleave learning <-> coding
cocreature 2017-02-11 01:44:44
monad-mad: becoming well-versed in the basics without writing code is going to be hard :)
monad-mad 2017-02-11 01:44:44
warrshrike: http://lpaste.net/new/haskell
warrshrike 2017-02-11 01:45:05
is it saying i should i assume those function exist and just give solution like that?