ishmael 2017-02-17 12:50:33
is myFunction :: a -> b an expression? or what is it?
haasn 2017-02-17 12:50:42
I have a function :: Double -> Double. What's the easiest/quickest way to visualize it, over a given input range?
haasn 2017-02-17 12:50:54
e.g. plot :: Double -> Double -> (Double -> Double) -> IO ()
`Guest05 2017-02-17 12:51:07
it's impossible to make a value `cast`able to two types right?
haasn 2017-02-17 12:51:16
I don't want to concern myself with setting up axes
jle` 2017-02-17 12:51:28
ishmael: depends on the context
EvanR 2017-02-17 12:51:32
cast ?
jle` 2017-02-17 12:51:34
ishmael: but at the top level, it's a type signature
jle` 2017-02-17 12:51:56
if it'as associated with a definition of 'myFunction', then it's a type signature
haasn 2017-02-17 12:52:02
ah https://hackage.haskell.org/package/easyplot-1.0/docs/Graphics-EasyPlot.html seems like my best bet
jle` 2017-02-17 12:52:05
but the same syntax also shows up in usage as an expression
buttons840 2017-02-17 12:52:15
I have a question about parsing with Trifecta -- if I have two parsers, p1 and p2, is "try (p1 <|> p2)" equivalent to "(try p1) <|> (try p2)" ?
ishmael 2017-02-17 12:52:24
jle`: im trying to understand that line of code in the context of a purely functional language
ishmael 2017-02-17 12:52:40
and i mean it as a type signature
jle` 2017-02-17 12:52:43
ishmael: it can show up as an expression too
`Guest05 2017-02-17 12:52:43
e. g. cast x :: Maybe A === Just something1 and cast x :: Maybe B === Just something2
jle` 2017-02-17 12:52:45
oh, ok
jle` 2017-02-17 12:52:50
ishmael: in that case, yes, it's a part of declaration syntax
jle` 2017-02-17 12:53:03
i'm assuming you don't mean something like (succ :: Int -> Int) 10
geekosaur 2017-02-17 12:53:06
ishmael: it's a type assertion. attached to a definition, it asserts the type of that definition; attached to an expression, it asserts that the expression must have that type
jle` 2017-02-17 12:53:14
where (succ :: Int -> Int) is an expression, 'succ' with a type annotation
EvanR 2017-02-17 12:53:29
`Guest05: what is the type of cast
jle` 2017-02-17 12:53:43
buttons840: i don't think it is
jle` 2017-02-17 12:53:43
i'm pretty sure it's not
jle` 2017-02-17 12:53:46
depending on p1 and p2
geekosaur 2017-02-17 12:53:52
(asserting the type of an expression may affect typeclass resolution, leading to an effect similar to "casting"; but it is not, itself, a cast)
`Guest05 2017-02-17 12:54:17
haasn: plot a b f = print $ f <$> [a,a+0.05..b]
jle` 2017-02-17 12:54:20
ishmael: in the context of a purely functional language, your program might simply be a bunch of (immutable) definitions/declarations
buttons840 2017-02-17 12:54:23
jle`: i think you are right, because i have experienced them behaving differently, but I'm not sure I understand why?
jle` 2017-02-17 12:54:36
ishmael: a type signature like that is a part of the syntax for defining/declaring somything
jle` 2017-02-17 12:54:43
it describes the declaration
jle` 2017-02-17 12:55:13
ishmael: similar to saying sin : R -> R; sin(x) = x - x^3/3! + x^5/5! + ...
jle` 2017-02-17 12:55:35
buttons840: 'p1 <|> p2' will try p2 if p1 fails, but it'll start parsing from when p1 left off
dolio 2017-02-17 12:55:52
No, that is not what happens.
jle` 2017-02-17 12:56:07
aw
buttons840 2017-02-17 12:56:24
jle`: oh, good to know
`Guest05 2017-02-17 12:56:45
haasn: or if you need to make it *visual*, plot f = print $ (/ 0.05) . (+ 1) . f <$> [-1,-0.95..1]
buttons840 2017-02-17 12:56:59
jle`: i figured "choose [p1, p2]" was the same as "p1 <|> p2", but it sounds like that's not the case?
ishmael 2017-02-17 12:57:23
jle`: ah, i see, so it's not really an expression on its own when it's part of a type signature, but it's part of the definition of the function
dolio 2017-02-17 12:57:27
try allows backtracking arbitrarily far.
jle` 2017-02-17 12:57:27
if p1 consumes input and then fails after consuming stuff, the, for p1 <|> p2, trifecta will start "running" p2 on the input that's already consumed
ishmael 2017-02-17 12:57:28
and the definition of the function is a function, right? one that returns the fuction?
`Guest05 2017-02-17 12:57:54
haasn: correction, plotVisual f = print $ (`replicate` '*') . truncate . (/ 0.05) . (+ 1) . f <$> [-1,-0.95..1]
dolio 2017-02-17 12:57:57
So, `try (p1 <|> p2)` is not able to do as much p1 backtracking as `(try p1) <|> (try p2)`.
jle` 2017-02-17 12:58:10
buttons840: choose [p1, p2] should be the same as p1 <|> p2, but i'm not 100% sure i remember the exact definition of choose
jle` 2017-02-17 12:58:18
but asum [p1,p2] is indeed p1 <|> p2
haasn 2017-02-17 12:58:24
`Guest05: it's alright, I already found my solution
haasn 2017-02-17 12:58:33
and I need this as a PNG for a blog post :)
haasn 2017-02-17 12:58:39
visual means visual
jle` 2017-02-17 12:58:43
ishmael: yes, it's a part of the syntax of defining something
ishmael 2017-02-17 12:59:15
jle`: and the definition is a function which returns itself?
jle` 2017-02-17 12:59:33
definition is not a function
jle` 2017-02-17 12:59:42
at least not in Haskell
buttons840 2017-02-17 12:59:42
choose = asum if I remember -- i'm not supper familiar with asum though
jle` 2017-02-17 12:59:59
it might be considered a function in a homoiconic language like lisp?
ishmael 2017-02-17 13:00:02
its an expression, though
jle` 2017-02-17 13:00:06
but definition/declaration is not a function
jle` 2017-02-17 13:00:09
it's not an expression, either
jle` 2017-02-17 13:00:18
declarations/definitions aren't considered expressions
jle` 2017-02-17 13:00:23
at least not in Haskell
jle` 2017-02-17 13:00:34
they are a wholly separate construct
EvanR 2017-02-17 13:00:58
declarations are not expressions, lets not speculate on what lisp thinks
lambdamu 2017-02-17 13:01:17
Hi, it is not possible to specify defaulting for arbitrary type classes with ExtendendDefaultRules, just a selected few, right?
ishmael 2017-02-17 13:01:34
jle`: why is that? that's how its implemented, or thats a difference in theory as well?
`Guest05 2017-02-17 13:01:44
:t cast
lambdabot 2017-02-17 13:01:45
(Typeable b, Typeable a) => a -> Maybe b
jle` 2017-02-17 13:01:49
well it's just how it is in the definition of Haskell
jle` 2017-02-17 13:01:58
in the language spec
EvanR 2017-02-17 13:02:21
`Guest05: then casst should work for multiple types
ishmael 2017-02-17 13:02:37
do they have different data structures?
jle` 2017-02-17 13:03:06
what data structures are you referring to?
`Guest05 2017-02-17 13:03:23
EvanR: how did you infer that from the type signature alone?
ishmael 2017-02-17 13:03:25
behind the scenes
jle` 2017-02-17 13:03:40
are you talking about how a compiler might implement an AST?
EvanR_ 2017-02-17 13:03:49
`Guest05: your ` is really annoying
`Guest05 2017-02-17 13:04:06
how?
EvanR_ 2017-02-17 13:04:22
i tried to type g, then ~ then...
EvanR_ 2017-02-17 13:04:38
all of which do stuff
jle` 2017-02-17 13:04:56
ishmael: in any case, the language spec is pretty clear that expressions and declarations are different concepts
ishmael 2017-02-17 13:04:56
jle`: in the C implementation (haskell is written in C, i think?)
jle` 2017-02-17 13:04:57
https://www.haskell.org/onlinereport/index.html
`Guest05 2017-02-17 13:05:04
EvanR_: sorry
jle` 2017-02-17 13:05:08
GHC is written in Haskell
`Guest05 2017-02-17 13:05:08
i'll note this
jle` 2017-02-17 13:05:16
and Haskell is written in English
`Guest05 2017-02-17 13:05:27
and English isn't written
jle` 2017-02-17 13:05:30
(provided in the link i gave)
jle` 2017-02-17 13:05:55
Haskell is a language specification; it's up to the implementations to decide how to...implement it
`Guest05 2017-02-17 13:06:08
chain = GHC : Haskell : English : []
jle` 2017-02-17 13:06:13
the spec itself is written in English, butI'm sure tere are versions transpiled to other languages
ishmael 2017-02-17 13:06:31
ok, well, i think that the runtime engine GHC uses is a C program
EvanR_ 2017-02-17 13:06:32
> cast 'a' :: Maybe Char
lambdabot 2017-02-17 13:06:34
Just 'a'
EvanR_ 2017-02-17 13:06:40
> cast 'a' :: Maybe Int
lambdabot 2017-02-17 13:06:42
Nothing
EvanR_ 2017-02-17 13:06:55
> cast (4::Int) :: Maybe Integer
jle` 2017-02-17 13:06:57
ishmael: sure, but what relevance is what language the runtime engine is written in, for your question?
lambdabot 2017-02-17 13:06:58
Nothing
EvanR_ 2017-02-17 13:07:01
maybe not
jle` 2017-02-17 13:07:05
are you asking about the AST that GHC parses the source code into?
jle` 2017-02-17 13:07:28
GHC parses haskell source code into an AST in Haskell, which presumably does differentiate expressions and declarations
jle` 2017-02-17 13:07:38
if only because expressions and declarations are different things in Haskell
EvanR_ 2017-02-17 13:07:41
ishmael: you can ask what the type of an expression is, but not what the type of a declaration is
EvanR_ 2017-02-17 13:08:01
you can evaluate an expression, but not a declaration
jle` 2017-02-17 13:08:06
expressions and declarations are just different concepts in Haskell
jle` 2017-02-17 13:08:26
the only similarity is that a haskell source file's text might contain both somewhere in them
EvanR_ 2017-02-17 13:08:58
the source text is an image of the AST
EvanR_ 2017-02-17 13:09:30
seeing it the other way might be delusional
jle` 2017-02-17 13:09:58
fair :)
`Guest05 2017-02-17 13:10:01
task: make AssertionFailed and AssertionFailedUser exchangeable, that is, for all A, B = any of them, fromException . toException :: A -> Maybe B returns Just ...
jle` 2017-02-17 13:10:14
although the haskell spec includes text/syntax rules for expressions and declarations
jle` 2017-02-17 13:10:29
so are those source text aspects a part of what an expression/declaration are?
ishmael 2017-02-17 13:11:02
ah, here is the answer to the question i was (or at least meant to ask)
EvanR_ 2017-02-17 13:11:22
geopardy time
`Guest05 2017-02-17 13:11:27
thing: how do i get (fromException :: SomeException -> Maybe AssertionFailed) to return Just ... for (toException $ AssertionFailedUser ...) ?
ishmael 2017-02-17 13:11:38
a value stored in a register or memory may have only one type: bit vector. However, bit vector is a polymorphic type and may come in several widths, e.g., bits8, bits32, or bits64. In addition to the bit-vector type C-- also provides a Boolean type bool, which can be computed by expressions and used for control flow but cannot be stored in a register or in memory.
EvanR_ 2017-02-17 13:11:41
er jeopardy
ishmael 2017-02-17 13:12:26
i should have said, "lower level," not "behind the scenes." the former has more meaning, i think
EvanR_ 2017-02-17 13:12:41
what does that have to do with declarations and expressions in haskell?
jle` 2017-02-17 13:12:50
if you're talking about runtime, neithre declarations nor expressions exist at runtime
`Guest05 2017-02-17 13:12:53
heh, is "more meaning" a total order?
ishmael 2017-02-17 13:12:58
i was wondering about their representation at execution time
jle` 2017-02-17 13:13:09
ah, yeah, at execution time, neither declarations nor expressions exist
EvanR_ 2017-02-17 13:13:22
types dont exist either
jle` 2017-02-17 13:13:23
only values
jle` 2017-02-17 13:13:31
well, for GHC, at least
EvanR_ 2017-02-17 13:13:44
values is a weird thing, runtime objects exist at runtime
jle` 2017-02-17 13:13:52
fair enough!
jle` 2017-02-17 13:14:01
in any case declarations and expressions definitely are not in the picture at all
ishmael 2017-02-17 13:14:23
jle`: do you mean for any language, or for haskell?
jle` 2017-02-17 13:14:23
they are aspects of haskell-the-language
jle` 2017-02-17 13:14:29
for Haskell
jle` 2017-02-17 13:14:36
they are semantic concepts of Haskell
jle` 2017-02-17 13:14:44
they don't have anything to do with what actually happens at runtime
ishmael 2017-02-17 13:14:45
ah, that's a great answer!
EvanR_ 2017-02-17 13:14:53
haskell is a high level language which can be compiled into a more efficient form for execution
ishmael 2017-02-17 13:15:04
and that explains why i was having such a hard time expressing my question
EvanR_ 2017-02-17 13:15:08
and that form looks way different
jle` 2017-02-17 13:15:28
yeah, you might be having a hard time separating the semantics of the language from how things are executed
jle` 2017-02-17 13:16:06
declarations and expressions are semantic concepts, but when a compiler wants to get things executed, they are both interpreted together to yield something runtimey
ishmael 2017-02-17 13:16:20
jle`: i still think like an imperative programmer. i just started learn you a haskell a week or two ago. first like real immersion into functional, or even higher level programming
EvanR 2017-02-17 13:16:58
the distinction should really be made in imperative languages too
EvanR 2017-02-17 13:17:08
one of many things you can take with you from haskell back to the real world
jle` 2017-02-17 13:17:18
maybe you can think of declarations and expressions as tools to write the recipe. when you actually cook a dish, you aren't expected to throw the ink and picture and paper into the pot
jle` 2017-02-17 13:17:32
just the things that they describe (like the ingredients)
ishmael 2017-02-17 13:18:04
right, so you can have a conceptual distinction between a declaration and an expression that is not recognized by the actual execution
EvanR 2017-02-17 13:18:25
you might think that C the language reflects real computer architecture better, but it doesnt, which is why you hear about "the C VM"
jle` 2017-02-17 13:18:28
yeah, the distintion is a semantic one
jle` 2017-02-17 13:18:38
re: the language, not the execution
EvanR 2017-02-17 13:19:37
once you realize a given language doesnt really reflect precisely what a computer will do, you get the non trivial question of what programs really mean
EvanR 2017-02-17 13:20:41
you can get abstract answers that better reflect ways to think about stuff, more useful ways
ishmael 2017-02-17 13:21:23
EvanR: C, like any programming language, is an abstraction of the lower level of implementation. if you assume that, C is less abstract than haskell, and is more directly analogous to what the machine does at runtime
EvanR 2017-02-17 13:21:45
i dont believe that, but we dont have a metric for this right now
jle` 2017-02-17 13:22:01
i don't think it's true that programming languages are an abstraction of lower level implementation
jle` 2017-02-17 13:22:11
in general
ishmael 2017-02-17 13:22:30
EvanR: you dont believe the assumption, or you think the conclusion is non sequitur?
EvanR_ 2017-02-17 13:22:48
none of it
buttons840 2017-02-17 13:23:24
I've been thinking a lot about a question from Bartosz Milewski (the category theory guy) who asked "Do we want to make programmers happy, or produce correct programs?"
jle` 2017-02-17 13:23:35
i'll admit that the need for programming languages came out of a desire of abstracting over lower level implementations
EvanR_ 2017-02-17 13:23:42
compiled c programs, with their implementation defined runtime systems dont have the concept of struct, defined macros, functions, linkage, etc
jle` 2017-02-17 13:23:49
and that might be a purpose that they are applied to
EvanR_ 2017-02-17 13:24:07
bitfields, trigraphs heh
ishmael 2017-02-17 13:24:08
EvanR_: you're saying, and i agree, that there is a inviolable distinction between a physical thing at the way we describe what it does
ishmael 2017-02-17 13:24:16
is that right?
EvanR_ 2017-02-17 13:24:30
"what it does" is one thing, "what a given program means" is another
EvanR_ 2017-02-17 13:24:47
even in C what it does is only a part
nshepperd_ 2017-02-17 13:24:48
buttons840: i hope that producing correct programs would make programmers happy!
EvanR_ 2017-02-17 13:24:56
a struct declaration does not do anything
ishmael 2017-02-17 13:25:11
it allocates memory
EvanR_ 2017-02-17 13:25:14
a main function definition doesnt do anything
EvanR_ 2017-02-17 13:25:17
no
ishmael 2017-02-17 13:25:31
oh, you mean at static time
EvanR_ 2017-02-17 13:25:39
what is "at static time"
jle` 2017-02-17 13:26:30
a struct declaration doesn't allocate memory... allocating a value of a given struct does
ishmael 2017-02-17 13:26:33
when the program is not executing
EvanR_ 2017-02-17 13:26:57
a declaration doesnt allocate memory ever
jle` 2017-02-17 13:27:00
if you declare a struct but never make any instances, it doesn't allocate any memory
buttons840 2017-02-17 13:27:19
nshepperd_: i would hope so too, but many seem to think it's too much work to be correct and instead want something that "just works"
buttons840 2017-02-17 13:27:49
"works [99.9% of the time] every time"
Profpatsch 2017-02-17 13:27:52
Gosh, the megaparsec docs for indentation are just so bad.
Profpatsch 2017-02-17 13:27:56
Or is that just me?
Profpatsch 2017-02-17 13:28:54
Most of it just doesn't parse for me, neither gramatically nor content-wise.
Profpatsch 2017-02-17 13:29:24
pun intended.
Profpatsch 2017-02-17 13:29:40
well, that was a lie.
ishmael 2017-02-17 13:31:02
jle`: when that code is executed, memory is allocated
ishmael 2017-02-17 13:31:06
in C at least
EvanR 2017-02-17 13:31:21
declarations dont correspond to anything at runtime
EvanR 2017-02-17 13:31:29
its like types in haskell
ishmael 2017-02-17 13:31:32
they do in C
ishmael 2017-02-17 13:31:40
when theyre executed, memory is allocated
EvanR 2017-02-17 13:31:42
no, you wont find it anywhere in memory
EvanR 2017-02-17 13:31:47
you dont execute declarations
EvanR 2017-02-17 13:31:55
you execute statements
buttons840 2017-02-17 13:32:45
the most recent example of working yet incorrect software was a coworker who wanted to write tabular data into a CSV, rather than dealing with quoting and escaping (which can handle ANY combination of characters), he's using "~|~" as a delimiter, because that would never appear in text on it's own, right? it's a difficult argument because his strategy has been very reliable, yet it is not correct
ishmael 2017-02-17 13:32:45
a declaration is a statement which requests a given amount of memory to be allocated on the stack
Profpatsch 2017-02-17 13:32:46
I'd say this here should parse integers indentedy by two spaces:
Profpatsch 2017-02-17 13:32:48
i = indentBlock (void spaceChar) (pure $ IndentSome (Just $ unsafePos 2) pure integer)
buttons840 2017-02-17 13:32:51
because there are certain valid inputs that will break everything
EvanR 2017-02-17 13:32:55
you could come up with the meaning of all these things, but thats not a good one
Profpatsch 2017-02-17 13:32:58
parseTest (i :: Parsec Dec String [Integer]) ""
Profpatsch 2017-02-17 13:33:18
But every conceivable input just errors out somehow
ishmael 2017-02-17 13:33:37
when int n; is executed, a word is allocated on the stack
EvanR 2017-02-17 13:33:53
no
ishmael 2017-02-17 13:34:15
not sure why you think that....
Tuplanolla 2017-02-17 13:34:15
If you read the C standard carefully, it doesn't even mention "stack" or "heap", ishmael.
EvanR 2017-02-17 13:34:16
well i am kind of sure why you think that, but if you wan more info on this you need to go to ##c
EvanR 2017-02-17 13:35:15
besides we were talking about struct declarations, not local variables
EvanR 2017-02-17 13:36:19
haskell declarations at the top level are similar, they dont do anything. but you might ask what they mean, and the haskell report explains it
ishmael 2017-02-17 13:36:31
write a c program int main { int i; printf("%i\n",i); return 0 }
ishmael 2017-02-17 13:36:38
it will compile and execute
EvanR 2017-02-17 13:37:28
struct A{ int i; }; int main { return 0; }
dmwit 2017-02-17 13:37:36
Is this argument related to Haskell?
EvanR 2017-02-17 13:37:46
##c
dmwit 2017-02-17 13:37:50
yes please
ishmael 2017-02-17 13:39:08
(and if you were to print the memory location of i, it wouldnt output "in theory") kbye
ishmael 2017-02-17 13:39:12
and thanks for your help!
ishmael 2017-02-17 13:39:20
w the haskell stuff, i mean
Tuplanolla 2017-02-17 13:42:00
I wonder why C attracts so much cargo cult knowledge about memory management.
Tuplanolla 2017-02-17 13:42:08
That never comes up here.
johnw 2017-02-17 13:42:22
when you think in terms of pointers and memory cells, it sort of follows naturally
jle` 2017-02-17 13:42:24
i think it tricks you into believing you know what's going on
monochrom 2017-02-17 13:42:39
Just wait until the next time someone has a "space leak" and ask here!
dmwit 2017-02-17 13:42:45
Tuplanolla: You're kidding, right? How many times have you dispelled the "no Haskell doesn't automatically memoize things" myth?
monochrom 2017-02-17 13:42:58
There will be cargo culting about thunks.
johnw 2017-02-17 13:43:16
yes, the common believe that all space leaks = too many thunks
monochrom 2017-02-17 13:43:54
In fact the whole etymology of so-called "space leak" is based on cargo culting on the "leak" word.
johnw 2017-02-17 13:44:12
so much cargo, so many cults
monochrom 2017-02-17 13:44:42
I now propose that we s/thunk/cargo/g
Tuplanolla 2017-02-17 13:44:44
Not once, dmwit, but now that I think about it, these things do come up occasionally.