Haskell, sequential program flow?

Apologies as this may seem like a very strange question. All my experience at haskell has been writing down functions that usually recursively evolve (and some data items decrease with each iteration). However, I have a set of functions, each of which performs some processing on a piece of data, and I wanted my call method to contain every step, for example

(Pseudocode)

myFunc1 :: Something1 -> Something2 execute myFunc1 Something1 . execute myFunc2 . execute myFunc3 . execute myFunc4 . return Something2 

But I'm not sure if this is possible? I just have to have something stupid:

myFunc4(myFunc3(myFunc2(MyFunc1(Something1)))) ?

EDIT: the above line may not be true!

+4
source share
2 answers

Use the $ function call statement:

 myFunc4 $ myFunc3 $ myFunc2 $ myFunc1 $ Something1 

Or the composition of the function:

 myFunc4 . myFunc3 . myFunc2 . myFunc1 $ Something1 

Or let :

 let x = myFunc1 Something1 in let y = myFunc2 x in let z = myFunc3 y in myFunc4 z 
+8
source

If you want to keep reading order from left to right, you can define

 (.>) = flip (.) -- are those in standard library somewhere? ($>) = flip ($) myComplex = Something1 $> myFunc1 .> myFunc2 .> myFunc3 .> myFunc4 
+3
source

Source: https://habr.com/ru/post/1380951/


All Articles