DEV Community

Cover image for Just 98 days of haskell :: Just once, Always
domagoj miskovic
domagoj miskovic

Posted on • Updated on

Just 98 days of haskell :: Just once, Always

Untyped universes of computational objects decompose naturally into subsets with uniform behaviour. Sets of objects with uniform behaviour may be named and are referred to as types. For example, all integers exhibit uniform behaviour by having the same set of applicable operations. Functions from integers to integers behave uniformly in that they apply to objects of a given type and produce values of a given type.

Alt Text

My 98th day of 100 days of code has extended into two days more, because conceptually I was still thinking about the basics of Haskell, the inner workings of algebraic data types . How would I represent this realization visually with types, how to translate it into some tangible form of logic and then into types. The rain was about to fall, sky was filling with shades of grey and I walk outside, the rain begins to fall, they offer me an umbrella but I happily enjoy the fall.

Alt Text

As concepts into questions arise, I feel the enormous pull of time, a single moment of a wave of stillness consumes my whole time, and days and night pass still pondering the same questions, object? What is an object. Maybe? What is Maybe and what is the difference between Either and Maybe, how do they relate to a Boolean value, a binary relation, and what do they actually represent, how come they are empty of themselves and serve as a context container, and why do I have to repeat myself, spin the same definition, find my own words to express the expression?

Maybe aDayLonger is Just aDayLonger or Nothing , as in we continue to the next day. Instead of productively working out some real life example, ready to be for production, a new idea, I end up basically thinking sum types and product types, which are types formed by combining other types, meaning Either or Maybe have no designated types, they are intrinsically not known, the main character of the types being in action, in the world, within the flow of data, either this or that, or maybe that implies a temporal dimension. They both embody a more complex form of two values, two fields, Either having two both equally possible values> Now what do I mean to say, I myself am still not clear, still trying to work on the learning to understand, to know, to realize the very beginning of journeying through the ocean of types. Either or Maybe seem like the basic building blocks, whose constructors build the world around us. For them to be free, pure agents of the function space learning functional programming and Haskell seems like adding richness to your own words, richness being defined by a pure relation with different kind of object with a related codomain.

data Maybe a = Just a | Nothing
Enter fullscreen mode Exit fullscreen mode

Maybe it is form of a computation of a type Maybe SomeTypeofaNumber, a number because it seems realizable, a number as another conceptual container, a type of a number, a Natural, an Int, a Double, a Float, like different set of a number within the range, our finite machine, from a pure primordial void comes the a, its letter being merely a designation, providing a conceptual complete space over our function, our choice, a selection, with an option to extend, to fill this space, I feel the most basic notion of minimal interaction with the outside world, a minimally described computation as a simple exchange between two values of a and b, either one or the other, both are possible, both ends could be the beginning, so it is writen a symbol of two things, Either a b or vocally meaning either a or b pointing towards could be Just 3 or Nothing, or Maybe Int could be Just 2 or Nothing, or Maybe String could be Just "hello" or Nothing, or Maybe Bool could be Just True or Nothing.

When I open a file, a link on an android operating system there are usually three apps available to choose from, saying Just once and AlwaysI sometimes chose one sometimes the other, I feel Just once, Always definition is very inclusive of its body, its description, then Just once, Nothing even though Always rings true to Just.

Alt Text

The Maybe datatype provides a way to make a safety wrapper around partial functions, that is, functions which can fail to work for a range of arguments. For example, head and tail only work with non-empty lists.

head [1,2,3,4]
1

tail [1,2,3,4]
2,3,4

myList = [1,2,3,4]
head myList
1

tail myList 
[2,3,4]

head []
*** Exception: Prelude.head: empty list
Enter fullscreen mode Exit fullscreen mode

Either seems like a different kind of computation, context container, a constellation of a greater number of possible values than Maybe, which can only hold or construct, two values, two computations which could be. Maybe shows something, a success or an error, True or Nothing, two basic boolean values, it shows Just something, Just a and an empty Nothing.

Searching takes me to an interesting Stack Overflow question on safety of head: https://stackoverflow.com/questions/6364409/why-does-haskells-head-crash-on-an-empty-list-or-why-doesnt-it-return-an

I might need a break, feeling the wave waning down, I might Just begin the 97th day from the beginning again.

Top comments (0)