Search Haskell Channel Logs

Saturday, February 11, 2017

#haskell channel featuring nitrix, Welkin, pavonia, lordcirth, geekosaur, Bish, and 12 others.

logzet 2017-02-11 05:45:21
First!
Welkin 2017-02-11 05:45:26
and you can do that same thing you are trying to do in a much simpler way using `filter` and `length`
Welkin 2017-02-11 05:46:41
> let countFigures = length . filter (`isElem` ['c', 'w']) in countFigures "abcdefgwc"
lambdabot 2017-02-11 05:46:45
error:
lambdabot 2017-02-11 05:46:45
Variable not in scope: isElem :: a -> [Char] -> Bool
Welkin 2017-02-11 05:47:27
> let countFigures = length . filter (`elem` ['c', 'w']) in countFigures "abcdefgwc"
lambdabot 2017-02-11 05:47:30
3
mangobot 2017-02-11 05:47:38
Welkin thanks!
Welkin 2017-02-11 05:48:00
when possible, avoid using if-then-else
Welkin 2017-02-11 05:48:08
it is not idiomatic and can be confusing
Welkin 2017-02-11 05:48:22
also remember that you must insclude the `else` when you do
Welkin 2017-02-11 05:48:26
include*
mangobot 2017-02-11 05:49:39
Welkin ok thanks!
mangobot 2017-02-11 05:50:49
Welkin can i ask another questions, ive been stuck on this for over 4h.. http://lpaste.net/352389 so the idea is to parse the string into different strings and the first one represents the board state. i thought to then seperate it into [[String]] and each list would = a row and then parse each list to locate the figures
mangobot 2017-02-11 05:51:13
Welkin but im failing to combine the functions so it would work this way, like in the commented function
zipper 2017-02-11 05:51:31
Welkin: Habari yako?
Welkin 2017-02-11 05:52:35
zipper: great, and you?
zipper 2017-02-11 05:52:51
Welkin: Great also :)
Welkin 2017-02-11 05:52:53
sorry, I haven't learned anything beyond that yet :P
Welkin 2017-02-11 05:53:49
mangobot: could you explain what your goal is?
Welkin 2017-02-11 05:54:09
there may be a simpler way to do it that you haven't thought about yet (like with the previous example)
cocreature 2017-02-11 05:54:51
mangobot: can you describe what a board is supposed to be? you probably also want to make a separate type for that
Welkin 2017-02-11 05:54:55
`initialFEN` is the board state?
Welkin 2017-02-11 05:55:25
and what are the '/''s for?
mangobot 2017-02-11 05:55:50
Welkin the goal is to parse a string like "b,b,b,b/b,b,b/b,b,b,b/,,/w,w,w,w/w,w,w/w,w,w,w w a3-c4" into 3 strings and 1 would be the boardstate which i could then parse into positions to iterate through the board and list possible moves. the 2 string would represent the next player and 3 the last move. in the string "," stands for next colm and / for next row
mangobot 2017-02-11 05:56:04
like here http://pjb.com.au/laska/play_laska.html
Welkin 2017-02-11 05:56:12
you are still describing what you want your solution to look like
Welkin 2017-02-11 05:56:19
what is the problem you are trying to solve here though?
Welkin 2017-02-11 05:56:29
I don't understand what the board represents
Welkin 2017-02-11 05:56:54
how does this string work as the board state? What is '/'?
mangobot 2017-02-11 05:58:22
Welkin / stands for next row, so as in the link b is black, "," indicates next column, another b etc. then next row = /, has 3 players etc. so parseBoard splits the string into list of strings and if there are 7 rows then there will be 7 lists with player positions
mangobot 2017-02-11 05:58:43
Welkin but that was just an idea to be able to locate each player by only using this string
Welkin 2017-02-11 05:59:01
okay
Welkin 2017-02-11 05:59:11
instead of working directly off of that string format
Welkin 2017-02-11 05:59:16
why not parse the board into an internal format
Welkin 2017-02-11 05:59:30
then if you want to export it to that same string format later, you can do so with one function
monochrom 2017-02-11 05:59:45
Because they came from Tcl :)
Welkin 2017-02-11 05:59:50
then you don't need to worry about parsing the board every time you want to evaluate it
mangobot 2017-02-11 06:00:26
Welkin yeah thats what i want to do, but not sure how to actually implement it, so thats why i thought to parse the string and get the coordinates from there
Welkin 2017-02-11 06:01:13
okay
Welkin 2017-02-11 06:01:24
and the space followed by a letter is the current player?
Welkin 2017-02-11 06:01:32
here's what you can do
mangobot 2017-02-11 06:01:40
Welkin yeah
mangobot 2017-02-11 06:01:56
Welkin and there also will be a a3-c4 for last move
Welkin 2017-02-11 06:02:00
parse all the data from the string up front, then your program only needs to operate on clean data, like a custom defined Player datatype and Board datatype
Welkin 2017-02-11 06:03:17
so the format is " " ?
mangobot 2017-02-11 06:03:28
Welkin could you give an example of how youd implement it? i was trying to do it for the whole day but just starte leaning haskell so it gets confusing with the data types etc
mangobot 2017-02-11 06:03:29
yeah
Welkin 2017-02-11 06:03:35
> lines " "
lambdabot 2017-02-11 06:03:38
[" "]
Welkin 2017-02-11 06:03:44
> words " "
lambdabot 2017-02-11 06:03:48
["","",""]
Welkin 2017-02-11 06:04:01
that will gives you the 3 parts that you need to continue parsing
Welkin 2017-02-11 06:04:28
> splitOn " " " "
lambdabot 2017-02-11 06:04:31
["","",""]
Welkin 2017-02-11 06:04:33
same thing
Welkin 2017-02-11 06:04:56
assuming the string that comes in is properly formatted
mangobot 2017-02-11 06:05:22
Welkin yeah i did it with parseFEN :: String -> [String] parseFEN = (splitOn " ") so it splits it into strings but failed to access each string afterwards
mangobot 2017-02-11 06:07:12
Welkin so i wanted to have something like http://lpaste.net/352389
monochrom 2017-02-11 06:08:40
@pl mu f = f (mu f)
lambdabot 2017-02-11 06:08:40
mu = fix (ap id)
zcourts 2017-02-11 06:10:41
is it possible (if so how?) to make a type assertion/constraint about all fields of a type? I mean, if I have a function f that takes some a, can I write a constraints that requires that fields in a are of some type T?
mangobot 2017-02-11 06:11:00
Welkin and have the listMoves and getMoves function in this format http://lpaste.net/352389
pavonia 2017-02-11 06:12:55
mangobot: Have you considered using a parser combinator library for the parsing stuff?
pavonia 2017-02-11 06:13:25
zcourts: By fields do you mean record fields?
bonnie 2017-02-11 06:14:18
hey guys I'm a haskell baby trying to understand why my code doesn't compile, could u help maybe?
bonnie 2017-02-11 06:14:36
tried to redefine the lines function
lordcirth 2017-02-11 06:14:49
bonnie, under the same name or different?
bonnie 2017-02-11 06:14:59
no different named it lines'
bonnie 2017-02-11 06:15:03
:)
lordcirth 2017-02-11 06:15:03
ok
zcourts 2017-02-11 06:15:26
yes, pavonia, record fields so if I were to have some type data X = X{c::X2, d::X3}, and a function f:: a -> Y. Can I write a constraint that requires that c and d in X are of type X2 and fail on anything else so in this example fail because d is of type X3 ?
lordcirth 2017-02-11 06:16:03
bonnie, well, pastebin the code and error
bonnie 2017-02-11 06:16:37
what is pastebin?sorry
pavonia 2017-02-11 06:16:51
zcourts: You could make define X like "data X a = X { c :: a, d :: a }" and then use the constraint on that type parameter
sandonfuge 2017-02-11 06:16:51
zcourts: you could do your function like this for example: sum :: (Num a) => a -> a -> a
sandonfuge 2017-02-11 06:16:57
if I understood you right, that is
lordcirth 2017-02-11 06:17:46
bonnie, pastebins are sites that let you upload text and get a link. https://bpaste.net/
geekosaur 2017-02-11 06:17:51
@paste
lambdabot 2017-02-11 06:17:51
Haskell pastebin: http://lpaste.net/
sandonfuge 2017-02-11 06:18:03
That forces a to implement Num, but I think that's not what you meant
lordcirth 2017-02-11 06:18:09
arg it's @? I tried ! and .
monochrom 2017-02-11 06:18:24
Or "data X a b = X{c::a, d::b}" then f can be "f :: X X2 X2 -> ..." but other places can still enjoy X X2 X3
bonnie 2017-02-11 06:18:28
lordcirth: https://bpaste.net/show/ed888c979460
geekosaur 2017-02-11 06:18:29
zcourts, that question only makes sense if Z is a typeclass instance, and even then I think you;d have to parameterize it with X2 and X3 for that question to make any sense
bonnie 2017-02-11 06:18:37
there it is
geekosaur 2017-02-11 06:18:51
otherwise it's just X as the type and the parameter is either that type or not
bonnie 2017-02-11 06:19:30
the problem must be in the "otherwise" line, i think i can't put the x: there
lordcirth 2017-02-11 06:20:03
your formatting is strange
geekosaur 2017-02-11 06:20:03
lordcirth, it's @ or ?
geekosaur 2017-02-11 06:20:38
I think that's 2 or 4 space tabs expanding to 8 on paste?
geekosaur 2017-02-11 06:21:01
or possibly something cut and pasted into vi with :set ai
zcourts 2017-02-11 06:21:54
pavonia: I figured as much on the type params but it's a lib so no control over the actual decls. sandonfuge geekosaur I'm currently using a typeclass to do it but got to the point where I was wondering if I was over complicating it
geekosaur 2017-02-11 06:21:55
bonnie, I think the problem is [ : ]
geekosaur 2017-02-11 06:22:06
as in the pattern, you probably want parentheses
geekosaur 2017-02-11 06:22:21
it's [x,y,z] or (x:y:z:[])
geekosaur 2017-02-11 06:22:26
[x:y] is a list of lists
bonnie 2017-02-11 06:23:05
geekosaur okay i will try that thanks!
Welkin 2017-02-11 06:24:50
mangobot: http://lpaste.net/352389
Welkin 2017-02-11 06:25:02
something like that
Welkin 2017-02-11 06:25:06
I'm missing a lot of information
Welkin 2017-02-11 06:25:13
but that is the basic idea for how to structure it
mangobot 2017-02-11 06:25:39
Welkin wow thanks! ill look through it now
mangobot 2017-02-11 06:29:32
Welkin yeah thats basically what i was trying to do. thanks for the example. so now i can apply these functions http://lpaste.net/352396 to get the coordinates and eventually get the move list and the best possible move
mangobot 2017-02-11 06:33:11
general question: why if defining something like data Move = Move Pos Pos, Move is used again but if something like data Type = W | B there is no need to write Type again?
Welkin 2017-02-11 06:33:51
to the left of the `=` is the Type
kosmikus 2017-02-11 06:33:52
monochrom: Move is the name of a data constructor, just like W and B are data constructors
Welkin 2017-02-11 06:33:57
to the right is the Data constructor
kosmikus 2017-02-11 06:33:59
mangobot: ^^
Welkin 2017-02-11 06:34:02
they are two different namespaces
kosmikus 2017-02-11 06:34:06
monochrom: sorry
monochrom 2017-02-11 06:34:10
The second "Move" is not a type. It's a data constructor and is in the same category as W and B.
monochrom 2017-02-11 06:34:40
You can also have "data Type = Type | NotType".
mangobot 2017-02-11 06:34:44
ah ok thanks a lot
monochrom 2017-02-11 06:34:49
This is the problem with meaningful names.
mangobot 2017-02-11 06:37:30
Welkin one more question, the last one! why is data Square = Empty | Occupied [Player] why is player a list?
Bish 2017-02-11 06:41:37
Helooooooo
Theophane 2017-02-11 06:42:01
sup
Bish 2017-02-11 06:42:25
Theophane: was joining to ask the obvious troll questions again but decided not to! whats up in here!?
Theophane 2017-02-11 06:43:09
I'm watching webcomics and fidgeting with Haskell and the Erlang VM
Bish 2017-02-11 06:43:33
funny thing is, that's partly the qesiton iwas going to ask
Bish 2017-02-11 06:43:40
then i remembered there is erlang
Bish 2017-02-11 06:43:53
( i was going to ask,why there aren't good functional language running on vm )
Bish 2017-02-11 06:44:00
which is not jvm. because that doesn't count
Theophane 2017-02-11 06:44:13
well, F# runs on a VM
Bish 2017-02-11 06:44:20
well microsoft does not count aswell
nitrix 2017-02-11 06:44:41
Hard to answer without a commonly agreed definition of "good".
Bish 2017-02-11 06:44:49
im wondering, i am not an expert on that level, just trying to find out if functional programming is something for me
Bish 2017-02-11 06:45:01
but shouldn't be functional languages easily be jit-able?
Welkin 2017-02-11 06:45:05
I don't see what a vm has to do with anything
ongy 2017-02-11 06:45:08
other question, why do you want it to run in a vm?