« first day (347 days earlier)      last day (114 days later) » 

10:37 AM
room topic changed to Haskell: Haskell. We endorse Alex' attempts to learn Haskell. [haskell]
@AlexM. there you go
 
yay
 
@AlexM. so yeah you can just x = 5 too
Haskell has Hindley-Milner type inference
it's much more powerful than auto in C++
 
googles
does haskell's type inference deal with proxy stuffs better than C++'s auto then?
e.g. the vector<bool> issue
 
@AlexM. it's a different thing.
remember that Haskell deals a lot with immutable types
you pass everything by value typically
you don't have to think about "referencing" anything, so proxies are less important in general
 
11:00 AM
I see
I think I wrote a factorial
myFunction :: Int -> Int
myFunction 0 = 1
myFunction n
 | n > 0 = n * myFunction(n - 1)
 | otherwise = 1

main = print(myFunction(5))
but I think the 0 case there is redundant
nvm it is
I like how you split things in particular cases like that
reminds me of prolog and functions in math
 
@AlexM. mostly the latter I suppose
@AlexM. also ewwww stop using those parens :S\
 
with myFunction(500) the thing printed 0
 
main = print $ myFunction 5
 
does haskell turn things into 0 when overflow happens or sth?
I expected it to go out of some int bounds
 
Prelude> let fac 0 = 1; fac n = n * fac (n-1)
Prelude> fac 500
122013682599111006870123878542304692625357434280319284219241358838584537315388199760549644750220328186301361647714820358
416337872207817720048078520515932928547790757193933060377296085908627042917454788242491272634430567017327076946106280231
045264421887878946575477714986349436778103764427403382736539747138647787849543848959553753799042324106127132698432774571
554630997720278101456108118837370953101635632443298702956389662891165897476957208792692887128178007026517450776841071962
@AlexM. go out into what
 
11:07 AM
doesn't Int have some limits
like 32 bit stuff
 
ah wait you added a signature again
 
like, this thing prints 0 for me
myFunction :: Int -> Int
myFunction n
 | n > 0 = n * myFunction(n - 1)
 | otherwise = 1

main = print(myFunction(500))
in the fpcomplete IDE thing
 
@AlexM. I can reproduce
 
@BartekBanachewicz so in your case I guess the deduced type is not Int
 
@AlexM. well if you remove the signature it should work because it will deduce Integer
 
11:09 AM
but something like BigInt or w/e
 
yeah, Integer
@AlexM. I think it's because if one multiplication ends on 0, every other will also be on 0
I mean, modulo Int size
 
the $ thing is actually prettier than the parens yep
 
@AlexM. yeah it makes the code much cleaner
 
in this context at least
parens seem to break the overall look
 
caveat: if you have more than one $ in one statement you're doing it wrong most probably
@AlexM. the cool thing about $ is that you have to add it just in one place; parens need both end and start
 
11:15 AM
awesome
I'm gonna try to do some simulated combat between a paladin and a troll
and see where I get
 
@AlexM. there's an article you might want to read in about a week or so
it'll be too advanced for a complete beginner, but I find it interesting.
even if, say, a little unorthodox in Haskell world
I'm not sure what style of learning do you prefer
like, more hands-on-and-do-things, or I-want-theory-first
 
I think it's the former because atm I paused the tutorial and instead I'm trying random stuff to see what breaks lol
 
12:14 PM
17
A: Haskell: multiple declarations of x

Ganesh SittampalamNo, this is not currently supported. The standard approach is to prefix each field with something unique to the particular datatype, e.g. p2x, p2y, p3x etc. The reason this isn't supported is that each record field name implicitly generates a "selector" function, e.g. x :: Point2 -> Float. Havin...

:(
so I can't do
data Troll = Troll { hitpoints :: Int, attack :: Int}
data Paladin = Paladin { hitpoints :: Int, attack :: Int }
 
@AlexM. 2 things for you to get right now
1) Haskell records are completely useless bullshit
2) Lens is the glory of dinosaur ninja power that was made to save us from haskell records
 
so if I want to do trolls vs paladins I don't do that data stuff and class Character c where c is troll or paladin
reading on lenses
 
@AlexM. you could do this:
data Troll = Troll { trollHitpoints :: Int }
data Paladin = Paladin { paladinHitpoints :: Int }

class HasHitpoints c where
    hp c :: Int

instance HasHitpoints Paladin where
    hp = paladinHitpoints

instance HasHitpoints Troll where
    hp = trollHitpoints
that's the "vanilla" haskell way
@AlexM. with Lens you can basically generate that automatically
and use in a sane way
 
I'll do vanilla so I can compare with lenses later
 
good idea
also I mistyped class def, should be hp :: c -> Int of course
 
12:53 PM
aren't you supposed to be able to make like constant instances of data stuffs?
tutorial says it works w/o the record (e.g. data Troll = Troll Int)
 
@AlexM. pardon me?
@AlexM. that's a "regular" data definition
 
I'm trying to do this
let myTroll = Troll { trollHitpoints = 34 }
here the guy was able to do let guy = Person "Buddy" "Finklestein" 43 184.2 "526-2928" "Chocolate" with Person being defined w/o the record stuffs
data Person = Person String String Int Float String String deriving (Show) basically
 
Prelude> data Troll = Troll { hp :: Int } deriving Show
Prelude> let t = Troll { hp = 100 }
Prelude> t
Troll {hp = 100}
@AlexM. and what seems to be the problem?
@AlexM. mm see that's what happens when you skip the tutorial
the thing is, the only difference between
 
data Troll = Troll { trollHitpoints :: Int } deriving (Show)
data Paladin = Paladin { paladinHitpoints :: Int } deriving (Show)

class HasHitpoints c where
    hp :: c -> Int

instance HasHitpoints Paladin where
    hp = paladinHitpoints

instance HasHitpoints Troll where
    hp = trollHitpoints

let myTroll = Troll { trollHitpoints = 34 }

main = print 5
says "Parse error (possibly incorrect indentation or mismatched brackets)"
 
data Troll = Troll Int
-- and
data Troll = Troll { hp :: Int }
is hp
 
12:57 PM
is my let outside of a function or sth?
 
@AlexM. maybe you have mismatched barteks somewhere
@AlexM. umm, in module scope you don't use let
look how main is defined
 
I got it to work :D
main = print $ hp Troll { trollHitpoints = 34 }
 
good job
 
so like class is some sort of base class
and instances are specific implementations
 
it's not a class in OOP meaning
 
1:00 PM
for particular types
 
@AlexM. more like an interface, if you will
@AlexM. yep
 
fuck yeah I got this
 
Haskell is eez
 
there are these quirks though that take me by surprise
 
like let?
 
1:03 PM
> Too many parameters for class Attack
(Use MultiParamTypeClasses to allow multi-parameter classes)
is this bad or sth?
using MultiParamTypeClasses
 
@AlexM. nope. perfectly fine.
 
what I want to do is
 
just enable the extension
 
class Attack attacker defender where
    attackResult :: attacker -> defender -> defender
 
{-% LANGUAGE MultiParamTypeClasses %-}
 
1:03 PM
so to do something like attackResult paladin troll that returns a troll that was attacked
 
@AlexM. mmmm
dunno if you want my input on your design at this point
beh, just experiment
@AlexM. there are some extensions that are perfectly safe to enable. I don't have a list right now though :(
{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE FlexibleContexts #-}
those should be OK
also beh it's # not %. Haven't coded anything in Haskell for too long
don't enable ones you don't need though obviously
FlexInstances is almost always necessary with MultiParamTypeClasses
@AlexM. if we were to talk design, though, fight between A and B might as well be A -> B -> (A, B)
 
is it a tuple
that'd be good for effects on both guys
 
yes, that's the tuple syntax
rather convenient
 
imma do this nicer after I learn stuff
I want to do the Maybe thing for cases when buffs exist on the weapons or not
 
lol, "the maybe thing"
Maybe basically turns a type into a type that can be either that type or nothing
 
1:13 PM
so it's not std::optional?
I mean isn't it the right thing for things that may be or not
 
@AlexM. it's more than std::optional, but you're not at Functors yet
@AlexM. that depends. Sometimes it makes sense to include that null in the original definition
consider:
data Buff = NoBuff | BuffA Int | BuffB Int
-- vs
data Buff = BuffA Int | BuffB Int
type PlayerBuff = Maybe Buff
 
holy shit it works
class Attack attacker defender where
    attackResult :: attacker -> defender -> defender

instance Attack Paladin Troll where
    attackResult pal trol = Troll { trollHitpoints = hitpoints trol - attackValue pal, trollAttack = attackValue trol }

main = print $ hitpoints $ attackResult Paladin { paladinHitpoints = 30, paladinAttack = 20 } Troll { trollHitpoints = 100, trollAttack = 30 }
I'm essentially a guru now
brb writing down Haskell on my CV
 
instance (Attack A B) => Attack B A where
    attackResult b a = attackResult a b
I think I got it right
2 hours ago, by Bartek Banachewicz
caveat: if you have more than one $ in one statement you're doing it wrong most probably
 
oh right
so that should be split in 3 statements or is something inherently wrong there?
 
@AlexM. f $ g $ h $ x == f . g . h $ x
 
1:25 PM
the latter is function composition right?
 
@AlexM. yes. $ is application, and . is composition
 
awesome
so much boilerplate for the class type thingies
 
1 hour ago, by Bartek Banachewicz
@AlexM. with Lens you can basically generate that automatically
 
yeah I was thinking about lenses now
 
4
Q: What's the difference between makeLenses and makeFields?

Bartek BanachewiczPretty self-explanatory. I know that makeClassy should create typeclasses, but I see no difference between the two. PS. Bonus points for explaining the default behaviour of both.

> makeFields creates a single class per field which is intended to be reused between all types that have a field with the given name. This is more of a solution to record field names not being able to be shared between types
@AlexM. cool you'll be ready to test Hate in no time
more users :>
 
1:33 PM
lol
now I know why you promote haskell
 
hahah
I made it for the people :(
but well there's not that much of interest
 
I guess it has to do with how unpopular haskell is in gamedev
 
@AlexM. there's not a lot of people so there's not a lot of libraries so there's not a lot of people, ....
 

« first day (347 days earlier)      last day (114 days later) »